Timed switch

Dependencies:   mbed

Committer:
faif
Date:
Sat Feb 11 18:39:32 2012 +0000
Revision:
0:5d9b6304f982
Child:
1:a523eaac3b7c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
faif 0:5d9b6304f982 1 #include "mbed.h"
faif 0:5d9b6304f982 2 #include "timed_switch.h"
faif 0:5d9b6304f982 3
faif 0:5d9b6304f982 4 int main (void)
faif 0:5d9b6304f982 5 {
faif 0:5d9b6304f982 6 t.start ();
faif 0:5d9b6304f982 7
faif 0:5d9b6304f982 8 while (True)
faif 0:5d9b6304f982 9 {
faif 0:5d9b6304f982 10 if (True == button)
faif 0:5d9b6304f982 11 {
faif 0:5d9b6304f982 12 // start counting time when the button is pressed
faif 0:5d9b6304f982 13 t.reset ();
faif 0:5d9b6304f982 14
faif 0:5d9b6304f982 15 // debouncing
faif 0:5d9b6304f982 16 while (True == button)
faif 0:5d9b6304f982 17 {
faif 0:5d9b6304f982 18 wait (wait_time);
faif 0:5d9b6304f982 19 }
faif 0:5d9b6304f982 20
faif 0:5d9b6304f982 21 // remove the debouncing delay from the counted time
faif 0:5d9b6304f982 22 button_holded = t.read_ms () - time_correction;
faif 0:5d9b6304f982 23
faif 0:5d9b6304f982 24 /* start couting time again and flashing the LED
faif 0:5d9b6304f982 25 after the button is released */
faif 0:5d9b6304f982 26 t.reset ();
faif 0:5d9b6304f982 27 while (t.read_ms () < button_holded)
faif 0:5d9b6304f982 28 {
faif 0:5d9b6304f982 29 myled = LedOn;
faif 0:5d9b6304f982 30 wait (wait_on);
faif 0:5d9b6304f982 31 myled = LedOff;
faif 0:5d9b6304f982 32 wait (wait_off);
faif 0:5d9b6304f982 33 }
faif 0:5d9b6304f982 34 }
faif 0:5d9b6304f982 35 }
faif 0:5d9b6304f982 36 }