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
Revision 2:ff5b9245e95e, committed 2014-05-15
- Comitter:
- valdub
- Date:
- Thu May 15 08:27:58 2014 +0000
- Parent:
- 1:03c191369089
- Commit message:
- Program published
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
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
diff -r 03c191369089 -r ff5b9245e95e mbed.bld --- a/mbed.bld Sun Jan 01 20:57:57 2012 +0000 +++ b/mbed.bld Thu May 15 08:27:58 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/078e4b97a13e +http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file