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 Simon Ford

Committer:
valdub
Date:
Thu May 15 08:27:58 2014 +0000
Revision:
2:ff5b9245e95e
Parent:
0:fb6bbc10ffa0
Program published

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:fb6bbc10ffa0 1 #include "mbed.h"
simon 0:fb6bbc10ffa0 2
valdub 2:ff5b9245e95e 3 InterruptIn button(USER_BUTTON);
simon 0:fb6bbc10ffa0 4 DigitalOut myled(LED1);
valdub 2:ff5b9245e95e 5 Timer debounce;
valdub 2:ff5b9245e95e 6
valdub 2:ff5b9245e95e 7 bool i = false;
valdub 2:ff5b9245e95e 8
valdub 2:ff5b9245e95e 9 void toggle()
valdub 2:ff5b9245e95e 10 {
valdub 2:ff5b9245e95e 11 if (debounce.read_ms()>100) {
valdub 2:ff5b9245e95e 12 i = !i;}
valdub 2:ff5b9245e95e 13 debounce.reset();
valdub 2:ff5b9245e95e 14 }
simon 0:fb6bbc10ffa0 15
valdub 2:ff5b9245e95e 16 int main()
valdub 2:ff5b9245e95e 17 {
valdub 2:ff5b9245e95e 18 myled = 1;
valdub 2:ff5b9245e95e 19 button.rise(&toggle);
valdub 2:ff5b9245e95e 20 debounce.start();
valdub 2:ff5b9245e95e 21 while(1)
valdub 2:ff5b9245e95e 22 {
valdub 2:ff5b9245e95e 23 if (i==true)
valdub 2:ff5b9245e95e 24 {
valdub 2:ff5b9245e95e 25 myled = !myled;
valdub 2:ff5b9245e95e 26 wait(0.2);
valdub 2:ff5b9245e95e 27 }
valdub 2:ff5b9245e95e 28 }
valdub 2:ff5b9245e95e 29 }