4 buttons on one analog input

Hi xoders I’m trying to input 4 buttons on one analog input using different resistance. Iv put a watch node on the analog read to find the readings of the different resistors and placed an equals to pick up the different buttons but it won’t change the Boolean from false to true can anyone help.

Many thanks Joeyjoejoe junior

Equal will seldom work with floating numbers. As far as Arduino is concerned, 0.1 is not equal to 0.1000000000000001

The obvious solution is to check for value between two values instead of equal to a specific value. Any check you perform would probably be more accurate if the values for the buttons were not so close together. It would be real easy if first button was less than 0.09, second button between 0.1 & 0.19, etc. Then you could multiply by 10 and take the integer (giving 0, 1, etc)

If you want to get fancy and check for multiple buttons pushed at the same time, then each button needs a carefully chosen value so that pressing multiple buttons still returns unique values, which can get very tricky… Resistance will go down since resistance of each button will be in parallel. The specific formula is 1/R = 1/X + 1/Y where X and Y are resistance of each button and R is the resistance of the two together.

Thanks gweimer was wondering if the values were to close together and if the equals would be able to pick them up.
Will have another go.

Many thanks

use a watch node connected to your val output and then you can just run in debug mode to see its value. also put a 1 sec clock on your loop.

The watch nodes are not going to provide infinity precision, so they will not give you an accurate value to use in the equal comparison. It is also likely that value for each button press will vary by a small amount each time if you were able to display infinite precision. Unless you first do some rounding of the number, using equal to evaluate analog input is not likely to work. The same will be true for evaluating results of division that results in a decimal of any length… There is likely to be some rounding errors converting between binary number stored by the computer and decimal number used by us mortals. In general… Don’t try to use equal with fractional numbers (floating point numbers in computer speak).

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