Computer engineering
Interrupts and event-driven code
An interrupt makes the processor pause its main program when an event happens, such as a pin changing or a timer expiring, and run a short handler function. This lets firmware react quickly without constantly checking. Handlers should be short: record what happened, set a flag and return, leaving slow work to the main loop. A variable shared between a handler and the main program should be declared volatile so the compiler always reads its current value, and updates that take several steps need protecting so a handler cannot interrupt them halfway.
Why it mattersCounting fast encoder pulses on a motor shaft is a classic job for an interrupt, because polling could miss them.