ISR: (pseudo code)
{
static uint8_t last_key_state = released;
static uint8_t debounced_key = released; // this may be a public variable if used else where
uint8_t key = read_key_state();
if (if key == pressed && last_key_state == pressed && debounced_key == released) // checks on a debounced ON_edge
{
debounced_key = pressed; // now debounced key = ON
out_pin = 3; // sets counter for 3 x 10ms timeout
}
if (last_key_state == released && key == released) // checks if key is released
{
debounced_key = released; // now it is debounced released
}
last_key_state = key; // just to memorize state for next run
if (out_pin > 0) // checks whether output should be ON
{
pin = ON; // set pin ON
out_pin--; // decrement counter
}
else // pin should be OFF
{
pin = OFF; // set pin OFF
}
}