execute a function when a button is pressed
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:49e04b14e729
diff -r 000000000000 -r 49e04b14e729 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 09 19:49:13 2016 +0000 @@ -0,0 +1,20 @@ +#include "mbed.h" // this tells us to load mbed related functions + +DigitalOut red(LED_RED); // we create a variable 'red', use it as an out port +DigitalOut green(LED_GREEN); // we create a variable 'green', use it as an out port + +InterruptIn btn2(SW2); // we create a variable 'btn2', use it as an in port +InterruptIn btn3(SW3); // we create a variable 'btn3', use it as an in port + +// YOUR CODE HERE + +// this code runs when the microcontroller starts up +int main() { + green = red = 1; // turn off green and red on startup (1=off, I know it's weird) + + btn2.fall(toggle_red); + btn3.fall(toggle_green); + + // spin in a main loop. Wait for interrupts. + while(1) {} +}