I have a simple sketch with a button that triggers an interruption set to happen when the button pin goes from HIGH to LOW. It has debouncing so no repetitions happen when the button is pressed, but sometimes when releasing the button the interruption also fires. Why would that be? Shouldn't the debouncing take care of any micro-rising during the release of the button?
volatile int contador = 0;
int n = contador;
long t = 0;
void setup() {
pinMode(2, INPUT_PULLUP);
attachInterrupt( 0, incrementaContador, FALLING);
}
void loop() {
if (n != contador) {
n = contador;
}
}
void incrementaContador() {
if ( millis() > (t + 50) ) {
contador++ ;
t = millis();
}
}
This same code works correctly when set to LOW instead of FALLING.
Shouldn't the debouncing take care of any micro-rising during the release of the button?
- That depends on the debouncing. Schematic please?