Section 9.2 Day 9 In-Class: A Button That Interrupts
Today we will look at a program that displays a count once a second and in addition is supposed to reset the counter on a button press. We will first run the polled version and observe where it misses button presses. Next we will configure the EXTI so that a falling edge on the button pin (PB4) raises an interrupt, then write the handler. With the button being able to interrupt, the counter resets the instant you press the button, even though the main loop spends almost all of its time inside a one-second delay.
At the end of class we’ll come back to something we have been doing since we started writing ISRs without examining it: changing a variable inside an ISR. It works in the programs we have written so far, and we’ll see why it can become problematic as soon as two pieces of code change the same variable.
