Sakis Kasampalis / Mbed 2 deprecated timed-switch

Dependencies:   mbed

Revision:
0:5d9b6304f982
Child:
1:a523eaac3b7c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/timed_switch.cpp	Sat Feb 11 18:39:32 2012 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+#include "timed_switch.h"
+
+int main (void) 
+{    
+    t.start ();
+    
+    while (True) 
+    {
+        if (True == button)
+        {
+            // start counting time when the button is pressed
+            t.reset ();
+            
+            // debouncing
+            while (True == button)
+            {
+                wait (wait_time);   
+            }
+            
+            // remove the debouncing delay from the counted time
+            button_holded = t.read_ms () - time_correction;
+            
+            /* start couting time again and flashing the LED 
+               after the button is released */
+            t.reset ();
+            while (t.read_ms () < button_holded)
+            {
+                myled = LedOn;
+                wait (wait_on);
+                myled = LedOff;
+                wait (wait_off);
+            }
+        }
+    }   
+}
\ No newline at end of file