-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button ADC Value is Zero #5
Comments
Looks like I figured out how to make a pull request on Github :) |
After merging your latest pull request I've applied another change which should achieve the same result without impacting the library performances. Will you be so kind to double check it works for you? Thanks UPDATE Forget about it, my improvement doesn't work and I have already reverted it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using a fairly common LCD + Button shield designed by DFRobot and available many other places. It has 5 buttons on A0 analog pin.
The problem I seem to be having is with the Right button not firing it's press or hold functions.
I believe the problem is because the right button has an ADC reading of 0 (ZERO).
When it gets to the following line:
if (reading >= buttons[i].value - margin && reading <= buttons[i].value + margin) {
The comparison fails with the following values being tested
reading:0
buttons[i].value - margin : 65526
buttons[i].value + margin : 10
By changing a couple of variable definitions to support unsigned integers seems to fix it.
Change the following lines, sorry I don't know how to make a pull request :(
to
int16_t reading = analogRead(pin);
AND
to
int16_t value;
I got the following values which fixed my problem.
reading:0
buttons[i].value - margin : -10
buttons[i].value + margin : 10
I'm interested in feedback on this code change, since I'm not much of a C programmer.
The text was updated successfully, but these errors were encountered: