Allume/éteint la LED quand on appuie sur le bouton
Dependencies: mbed
Fork of Allumage_LED by
main.cpp@0:c72f09731dd4, 2014-05-15 (annotated)
- Committer:
- valdub
- Date:
- Thu May 15 08:23:02 2014 +0000
- Revision:
- 0:c72f09731dd4
Program published
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
valdub | 0:c72f09731dd4 | 1 | #include "mbed.h" |
valdub | 0:c72f09731dd4 | 2 | |
valdub | 0:c72f09731dd4 | 3 | DigitalOut myled(LED1); |
valdub | 0:c72f09731dd4 | 4 | InterruptIn button(USER_BUTTON); |
valdub | 0:c72f09731dd4 | 5 | Timer debounce; |
valdub | 0:c72f09731dd4 | 6 | |
valdub | 0:c72f09731dd4 | 7 | int i=0; |
valdub | 0:c72f09731dd4 | 8 | |
valdub | 0:c72f09731dd4 | 9 | void toggle() |
valdub | 0:c72f09731dd4 | 10 | { |
valdub | 0:c72f09731dd4 | 11 | if (debounce.read_ms() > 100) { |
valdub | 0:c72f09731dd4 | 12 | i = !i; } |
valdub | 0:c72f09731dd4 | 13 | debounce.reset(); |
valdub | 0:c72f09731dd4 | 14 | } |
valdub | 0:c72f09731dd4 | 15 | |
valdub | 0:c72f09731dd4 | 16 | int main() |
valdub | 0:c72f09731dd4 | 17 | { |
valdub | 0:c72f09731dd4 | 18 | myled = 0; |
valdub | 0:c72f09731dd4 | 19 | button.rise( &toggle ); |
valdub | 0:c72f09731dd4 | 20 | debounce.start(); |
valdub | 0:c72f09731dd4 | 21 | |
valdub | 0:c72f09731dd4 | 22 | while (1) |
valdub | 0:c72f09731dd4 | 23 | { |
valdub | 0:c72f09731dd4 | 24 | myled = (i == true) ?1 :0; |
valdub | 0:c72f09731dd4 | 25 | } |
valdub | 0:c72f09731dd4 | 26 | } |