Skip to content
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

Closed
fraser125 opened this issue Apr 16, 2017 · 2 comments
Closed

Button ADC Value is Zero #5

fraser125 opened this issue Apr 16, 2017 · 2 comments

Comments

@fraser125
Copy link
Contributor

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 :(

void AnalogButtons::check() {
/* other misc lines */
      uint16_t reading = analogRead(pin);

to
int16_t reading = analogRead(pin);

AND

class Button {
public:
	uint16_t value;

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.

@fraser125
Copy link
Contributor Author

Looks like I figured out how to make a pull request on Github :)

@rlogiacco
Copy link
Owner

rlogiacco commented Apr 21, 2017

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants