Problems with joystick/potentiometer analog ports


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 /

How can I solve the problem?

Try using gate(pulse) to control, instead of using if-else, and use joystick-x-y-button-all


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).

but this could well be done, with the data obtained, and send a default value without touching the port.


and keeping the last value something like that

1 Like


Thank you for your responses. I will definitely try your suggestions.

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.

Perhaps the problem is also in the board. I tried UNO again. When the port was blocked, the value did not rise above 0.68.

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.

Thanks for your reply.

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.

Perhaps all this can be implemented easier, but I have just started using XOD and have not yet come up with a different option.

You can try something like this, the counter increases and decreases, if it rises or falls of a certain value.


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.


Thanks for your answer, I will definitely try this option.

Thanks again for the help. Now everything works as needed.

1 Like

Started testing nth-input. I don’t know if it will work but it looks beautiful. :grinning:

1 Like

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.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.