Here is the issue : ScreenChoice should increase each time i push the button. But it increses twice, when I touch the button and when I lift my finger.
Hmm... Perhaps the device shows the equivalent of "switch bounce". If so, there might sometimes be more than two changes with one touch or one release.
Riva:
What happens if you turn on the internal pullup resistor.
pinMode(3, INPUT_PULLUP);
Nothing has changed
jremington:
Hmm... Perhaps the device shows the equivalent of "switch bounce". If so, there might sometimes be more than two changes with one touch or one release.
Does ScreenChoice always increment by exactly 2?
You are true, I haven't noticed that as my "true" code is a bit different, but most of the time it increase by 3 or 4, and rarely by 2 and more than 4, but never by one.
It does sound like the equivalent of switch bounce. Most likely, there is a comparator measuring voltage levels, and noise on the input line causes multiple transitions on the output.
There are lots of posts on this forum, and even a library to deal with switch bounce.
void setup() {
// Setup the button with an internal pull-up :
pinMode(BUTTON_PIN,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
debouncer.attach(BUTTON_PIN);
debouncer.interval(5); // interval in ms
}
void loop() {
// Update the Bounce instance :
debouncer.update();
// Get the updated value :
int value = debouncer.read();
}
It seems easy to use, but, how do i can implement it in my :
attachInterrupt (1, button_push, FALLING);
EDIT2 :
Maybe I should do it this way :
but, i will have to train to determine the debouncing time which fit the best!