I'm quite new to AVR programming (avr-gcc).
To react on button-press, I am using a PCINT ISR with the internal pull-up resistor enabled like this:
ISR(PCINT0_vect) {
if (bit_is_clear(PINB, PB0)) {
_delay_ms(40);
if (bit_is_clear(PINB, PB0)) {
// do something
}
}
}
It works okay but I guess it is not particularly smart to spend 40 milliseconds in an ISR just to debounce a button.
I have read Ganssle's Debouncing Contacts Part 2 which is a bit too advanced for my current level of experience, and there is one statement that I am not sure about:
The undebounced switch must connect to a programmed I/O pin, never to an interrupt.
So is my approach to connect the button to a PCINT already wrong? I haven't gotten around timers yet, but should I rather use some kind of timed interrupt to evaluate the button state every 1 ms or so instead of the button triggering an interrupt directly?
I can live with my debouncing not being very smart for now, but at least I want to get the basics of reacting on a button-press right.