An active blinking led program (without the delay causes from the use of wait() function)

Dependencies:   mbed

Revision:
0:33741587427a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 08 20:10:18 2014 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+ 
+const long interval = 1000; // Time between blink (1s)
+ 
+int main()
+{
+    Timer timer;                                      // Create the Timer object
+    DigitalOut led(LED1, 0);                          // Create the LED object and setup OFF
+    unsigned long currentMillis, previousMillis;      // Variables for time reading
+
+    timer.start();                                    // Start the Timer
+    previousMillis = timer.read_ms();                 // Read the actual time
+    while(1)
+    {
+        currentMillis = timer.read_ms();              // Read the actual time
+        if(currentMillis - previousMillis > interval) // Compare if the time between blink has success (interval == 1s)
+        {
+            led = !led;                               // Toggle the LED state
+            previousMillis = currentMillis;           // Save the last time you toggle the LED 
+        }
+    }
+}
\ No newline at end of file