Switch a LED by two button interrupt (b_on and b_off)

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 InterruptIn b_on(PC_10);       // Pusbutton input (PC_10)
00004 InterruptIn b_off(PC_12);      // Pusbutton input (PC_12)
00005 DigitalOut led(LED1);          // LED output (PA_5)
00006 
00007 void b_on_pressed() {
00008     led = 1;                   // LED on
00009 }
00010 
00011 void b_off_pressed() {
00012     led = 0;                   // LED off
00013 }
00014 
00015 int main() {
00016     b_on.mode(PullUp);         // Enable internal pullup
00017     b_on.fall(&b_on_pressed);  // Attach function to falling edge
00018     b_off.mode(PullUp);        // Enable internal pullup
00019     b_off.fall(&b_off_pressed); // Attach function to falling edge
00020     while (true) {
00021         wait(0.2f);            // Nothing to do. Just wait
00022     }
00023 }