Blinking a LED using the timer (timeout object)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jose_23991
Date:
Wed Oct 29 20:25:48 2014 +0000
Commit message:
Version 1.0

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 29 20:25:48 2014 +0000
@@ -0,0 +1,18 @@
+#include "mbed.h"
+
+#define TIME 1                              // Time for toggle the LED (seconds)
+
+DigitalOut led(LED1, 0);                    // Create the LED object and setup OFF
+Timeout timeout;                            // Create the Timeout object
+    
+void timer_interrupt()
+{
+    led = !led;                             // Toggle the LED state
+    timeout.attach(&timer_interrupt, TIME); // Set again the timer timeout for next iterations
+}
+ 
+int main()
+{    
+    timeout.attach(&timer_interrupt, TIME); // Set the timer interrupt service rutine (ISR) and the time for the timeout (in seconds)
+    while(1);                               // Infinite loop
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 29 20:25:48 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file