Trying to create a menu on the OLED display. But, I ran into a problem when changing the name of the ports (active/inactive). Data continues to be read despite the fact that the port is incorrect. The joystick is connected to ports A0 and A1.
To change the name of the ports, you must press the joystick / button. For the joystick, I use the library 315821 / joystick-x-y-button /
NOTE: Some nodes initialize on startup and won’t update port/etc. after that, so code like yours above would never switch ports. This is probably rare and is not the case with the joystick node (but you have to drill down to the C++ code in analog-read to know that for sure).
Changing to an “invalid” port isn’t going to keep data from being read. It is just going to read the data from a different port. If that port isn’t connected to anything, the value is going to float. Internal circuits might drain or charge the port; any static electricity might affect it, etc. and it can change dramatically between each read (or it might stay the same value—there is no way to know and it might work differently the next time you use it).
I think in XOD, the closest you can come to “no value” is to stop changing the value. That can be done as cesars showed above by only telling the joystick to update when it is active (the node you are using just assumes it should always update; the -all node exposes the update pins so you can control that). It can also be done by using gate or buffer nodes on the output. There are probably other options as well, but these are the most “conventional” methods in XOD. Which option is “better” might depend on your other code. If there was no option to use the UPD pins, then it obviously would not be the “right” answer. Other code might already be solving most of the problem for you using one solution, but not the other. In general, if not allowing update (like cesars’ solution) is an option, it is probably the better solution than adding gate or buffer nodes to the output; it generally means the Arduino will have less work to do since some of the code (in this case what is in the joystick node) doesn’t have to execute if UPD pin doesn’t pulse.
In the case of using A15, it gives me the same error as if I were using D255 (pin not valid). I do not know why the error is not reflected there, perhaps it is another board.
Here is an example of using D255 and ignoring the error, sending a default value (0).
Yesterday I tried to use the base nodes, but the problem persisted. I also tried to change the board, from MEGA 2560 to UNO, and this also did not solve the problem.
What is also interesting, when using MEGA, when the port is blocked, only one direction works (horizontal/vertical) , but the calculation is carried out for two ports.
But there is using A5, A5 surely when not using this non-floating mode and will take a random value.
As I said before recommend handling the data instead of ports.
All I’m trying to do: start a menu - allow the joystick to move only vertically - press a button - go to a submenu - the joystick moves only horizontally - press a button again - save data and return to the main menu. And so my problem was that after pressing the button the vertically direction of the joystick is not blocked.
To move around the menu, I use the node count, and to determine the position by the equal node.
Rather than duplicating your menu display code for each display option, you might be able to use one copy of display and change what is being displayed. Since you already have X/Y counters to determine what to display, nth-input can probably be used:
This assumes you are at the main menu when CNT_X=0. If CNT_X>0, then you are on a sub-menu. If different sub-menus are different sizes, you can use another nth-input to set MAX_X for each value of CNT_Y and resize each nth-input appropriately.
nth-input works very well, only if you use too much the consumption of resources is very large.
That is why I modified in my library so that it consumes less, the integration in the development generated some errors and abandoned the idea since I do not handle my github well for that.
The menu system has constants that you can edit to use in conjunction with nth-input. Those values ​​use flash-string-1, which is explained by @bitrex
ps: It can be somewhat complex, because each menu requires a flash-string.
Then you have to clone it as many times as necessary. without modifying the library.