debounce problem

dhenry:

But that counter is advanced by timer0 ISR

That is not correct. The counter (TMR0) is advanced by hardware.

Based on wiring.c, delay utilizes micros(), which tests TMR0 interrupt flag. So from that perspective, using delay() within isr is OK.

As I said, I needed to check wiring.c more carefully :stuck_out_tongue: Thanks for pointing this out.

dhenry:
micros() interestingly disables global interrupt upon entry but never re-enable it upon exit.

SREG is saved before disabling interrupts. It is then restored to its saved value upon exit. The global interrupt enable flag thus returns to its "enabled" state.