Blinking a LED using the timer (timeout object)

Dependencies:   mbed

Committer:
jose_23991
Date:
Wed Oct 29 20:25:48 2014 +0000
Revision:
0:7eabe79006b3
Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jose_23991 0:7eabe79006b3 1 #include "mbed.h"
jose_23991 0:7eabe79006b3 2
jose_23991 0:7eabe79006b3 3 #define TIME 1 // Time for toggle the LED (seconds)
jose_23991 0:7eabe79006b3 4
jose_23991 0:7eabe79006b3 5 DigitalOut led(LED1, 0); // Create the LED object and setup OFF
jose_23991 0:7eabe79006b3 6 Timeout timeout; // Create the Timeout object
jose_23991 0:7eabe79006b3 7
jose_23991 0:7eabe79006b3 8 void timer_interrupt()
jose_23991 0:7eabe79006b3 9 {
jose_23991 0:7eabe79006b3 10 led = !led; // Toggle the LED state
jose_23991 0:7eabe79006b3 11 timeout.attach(&timer_interrupt, TIME); // Set again the timer timeout for next iterations
jose_23991 0:7eabe79006b3 12 }
jose_23991 0:7eabe79006b3 13
jose_23991 0:7eabe79006b3 14 int main()
jose_23991 0:7eabe79006b3 15 {
jose_23991 0:7eabe79006b3 16 timeout.attach(&timer_interrupt, TIME); // Set the timer interrupt service rutine (ISR) and the time for the timeout (in seconds)
jose_23991 0:7eabe79006b3 17 while(1); // Infinite loop
jose_23991 0:7eabe79006b3 18 }