Posts about avr

, , ,

Arduino Interrupts and Timers

Outside of the traditional method of gathering values from Arduino inputs, there are a couple of other excellent tools in the workshop we can use. Interrupts provide the means to allow hardware devices to trigger a routine in your sketch and perform additional processing outside of the main loop. This trigger usually happens when an input changes state, allowing you to monitor an input pin without having to check it each time the main loop runs. Timers provide a way to run code at predefined intervals outside the main loop. Instead of calling millis() during the loop and constantly checking whether enough time has passed, you can create timers to move that logic outside of the main program execution. Just like hardware interrupts, a timer interrupt runs asynchronously and independent of the main loop.