Sakis Kasampalis
/
two-way-switch
toggle button style
Diff: two_way_switch.cpp
- Revision:
- 0:ccd27d3bca28
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/two_way_switch.cpp Sun Mar 15 17:23:48 2015 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "two_way_switch.h" + +int main (void) +{ + DigitalOut state = myled; + + while (true) + { + if (button) + { + /* toggle the state of the led */ + toggle_state(state); + + /* to avoid the bouncing effect */ + while (button) + { + wait(BOUNCE_DELAY); + } + } + } +} + +void toggle_state(DigitalOut& s) +{ + switch(s) + { + case true: + s = false; + break; + case false: + s = true; + break; + } +} \ No newline at end of file