My current setup has the arduino in 'stand-by' power saving mode, therefore i am unable to use any means of a traditional soft debouncer, such as Bounce2, as far as I know.
I went ahead and attached the buttons to pin change interrupts, since I have one button on each bank, i.e. pin 7 and pin 11.
The technique I'm using doesn't seem to be behaving since the routines are being fired too regularly (inconsistently), and at the rising edge too.
I have the pins set to use their internal pull-ups.
Using the PCI library:
void pciSetup(byte pin)
{
*digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin
PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the
pciSetup(POWER_SWITCH);
pciSetup(SELECTOR_BTN);
// check if IR IN or Power switch
ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{
if (digitalRead(POWER_SWITCH) == LOW)
{
noInterrupts();
unsigned long last_millis = millis();
while (millis() - last_millis >= 500);
ir_power_pressed = true;
}
interrupts();
}
ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7
noInterrupts();
unsigned long last_millis = millis();
while (millis() - last_millis >= 500);
ir_selector_pressed = true;
interrupts();
}
Am I doing something silly?
Update 1
As suggested in the comments, i've adjusted the code, but it still triggers on the rising edge, and a few times rapidly at the falling edge.
ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7 here
{
if (digitalRead(SELECTOR_BTN) == LOW)
{
noInterrupts();
static unsigned long last_millis = millis();
if (millis() - last_millis >= 500)
{
ir_selector_pressed = true;
interrupts();
}
}
}
last_millis
static, and replace the while loop with an if statement.