Button control led blink

Dependencies:   mbed

Committer:
szqt
Date:
Sun Jul 03 15:07:34 2016 +0000
Revision:
1:03f6bcfaacf8
Parent:
0:c9d8fcdda4d0
fast flash led

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:c9d8fcdda4d0 1 #include "mbed.h"
bcostm 0:c9d8fcdda4d0 2
bcostm 0:c9d8fcdda4d0 3 DigitalIn mybutton(USER_BUTTON);
bcostm 0:c9d8fcdda4d0 4 DigitalOut myled(LED1);
bcostm 0:c9d8fcdda4d0 5
bcostm 0:c9d8fcdda4d0 6 int main() {
bcostm 0:c9d8fcdda4d0 7 while(1) {
bcostm 0:c9d8fcdda4d0 8 if (mybutton == 0) { // Button is pressed
bcostm 0:c9d8fcdda4d0 9 myled = !myled; // Toggle the LED state
szqt 1:03f6bcfaacf8 10 wait(0.1); // 100 ms
szqt 1:03f6bcfaacf8 11 }
szqt 1:03f6bcfaacf8 12 else {
szqt 1:03f6bcfaacf8 13 myled = 1; // LED is ON
szqt 1:03f6bcfaacf8 14 wait(0.2); // 200 ms
szqt 1:03f6bcfaacf8 15 myled = 0; // LED is OFF
szqt 1:03f6bcfaacf8 16 wait(1.0); // 1 sec
bcostm 0:c9d8fcdda4d0 17 }
bcostm 0:c9d8fcdda4d0 18 }
bcostm 0:c9d8fcdda4d0 19 }
bcostm 0:c9d8fcdda4d0 20