Electronics Bash – #18- Timers

To this point, we’ve been handling all of the timing and timekeeping in our Arduino programs by hand. If the-next-thing needs to happen at a specific time, or a specific number of milliseconds from now, we’ve been tracking all that with variables and millis() statements and so on. What if there wa a way for that all to be taken care of in the background, automatically? And what if it was something we’d been doing all along without our knowing it?

Topics Include:

  • Timers in the ATmega328
  • Timer Interrupts and Configuration
  • Timers and built-in Functions (AnalogWrite, Tone, Millis, Delay, Servo)
  • Using timers to build new code

Code

Print Timer

Print Timer Interrupts

Blink Interrupts

Adjustable Speed Blink

The following code will make use of the above circuit diagram

Tone Interrupts

Tone Interrupts – Serial

Tone List

Pitches.h

The following code will make use of the above circuit diagram

SnakeMusic.ino