Tuesday, June 28, 2022

LED Blinking using TimerOne Library of Arduino

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.

Blinking an LED using Timer1 Library of Arduino
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.

  1. #include <TimerOne.h>
  2.  
  3. void setup(){
  4. pinMode(13,OUTPUT);
  5. //set timer 1 duration to 250ms
  6. Timer1.initialize(250000);
  7. //Interrupt Handling
  8. Timer1.attachInterrupt(blinkLed);
  9. }
  10.  
  11. void loop(){
  12.  
  13. }
  14.  
  15. bool state=false;
  16. void blinkLed(){
  17. digitalWrite(13,state);
  18. state^=1;
  19. }

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.

No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)