The Arduino Uno is typically powered by the Atmega328. It has Timer/Counter1 module to make a timing or counting process. To access this timer module, the programmer needs to install a library for timer1. This timer library can be used to create a timing delay, or a PWM signal, etc.
Running program on board |
In this example, I use this timer library to blinking an LED. This library has a timer interrupt for a specific period. So we can use its timer interrupt to create a timing tick. Using this feature the main program loop doesn't need to wait for any duration. It has an advantage rather than using the Millis(), or delay function library of the Arduino.
#include <TimerOne.h> void setup(){ pinMode(13,OUTPUT); //set timer 1 duration to 250ms Timer1.initialize(250000); //Interrupt Handling Timer1.attachInterrupt(blinkLed); } void loop(){ } bool state=false; void blinkLed(){ digitalWrite(13,state); state^=1; }
I don't draw its schematic here because this example use only the BUILD-IN LED of the Arduino Uno board.
Click here to download this example.