Timers

Led blinking using timer

Description

changes the led state every 1 second without delay leaving the void loop() for executing other code

Connection

a Led is connected through a 330 resistance to pin 4 on C

Code

(:source:)

 #include <Timer.h>
 #define led_pin WC4
 bool led_state=0

Timers_class Timer; void setup() { Timer.begin();

  Timer.periodic(1000,Change_Led_state,1); //Change_Led_state is called every 1000ms
  pinMode(led_pin, OUTPUT);

}

void loop() { // put your code here }

bool Change_Led_state() { led_state = ! led_state ; digitalWrite(led_pin,led_state); return 0 ; }

(:sourceend:)

  

Share |