Button control led blink

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 DigitalIn mybutton(USER_BUTTON);
00004 DigitalOut myled(LED1);
00005  
00006 int main() {
00007   while(1) {
00008     if (mybutton == 0) { // Button is pressed
00009       myled = !myled; // Toggle the LED state
00010       wait(0.1); // 100 ms
00011     }
00012    else {
00013         myled = 1; // LED is ON
00014         wait(0.2); // 200 ms
00015         myled = 0; // LED is OFF
00016         wait(1.0); // 1 sec
00017     }
00018   }
00019 }
00020