Fait clignoter la LED quand on appuie sur le bouton, et l'arrête dans son dernier état quand on appuie de nouveau.
Dependencies: mbed
Fork of HelloWorld by
Diff: main.cpp
- Revision:
- 2:ff5b9245e95e
- Parent:
- 0:fb6bbc10ffa0
diff -r 03c191369089 -r ff5b9245e95e main.cpp --- a/main.cpp Sun Jan 01 20:57:57 2012 +0000 +++ b/main.cpp Thu May 15 08:27:58 2014 +0000 @@ -1,12 +1,29 @@ #include "mbed.h" +InterruptIn button(USER_BUTTON); DigitalOut myled(LED1); +Timer debounce; + +bool i = false; + +void toggle() +{ + if (debounce.read_ms()>100) { + i = !i;} + debounce.reset(); +} -int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } -} +int main() +{ + myled = 1; + button.rise(&toggle); + debounce.start(); + while(1) + { + if (i==true) + { + myled = !myled; + wait(0.2); + } + } +} \ No newline at end of file