Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: timed_switch.cpp
- 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