it is relatively easy to notice a button push using an interrupt and ignoring any bounciness...
not tested, not compiled
volatile bool buttonPushed = false;
void setup()
{
attachInterrupt(1, PushButton, RISING); // May need to change
}
void loop()
{
if(buttonPushed)
{
buttonPushed = false;
// do something
}
}
void PushButton() //interrupt with debounce
{
volatile static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 50UL) // ignores interupts for 50milliseconds
{
buttonPushed = true;
}
last_interrupt_time = interrupt_time;
}
I use it for example when working with blocking code (radio TX, and RX). And need to notice an event happened.