execute a function when a button is pressed
Dependencies: mbed
main.cpp@0:49e04b14e729, 2016-05-09 (annotated)
- Committer:
- maclobdell
- Date:
- Mon May 09 19:49:13 2016 +0000
- Revision:
- 0:49e04b14e729
initial version - modified from https://github.com/janjongboom/sxsw
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maclobdell | 0:49e04b14e729 | 1 | #include "mbed.h" // this tells us to load mbed related functions |
maclobdell | 0:49e04b14e729 | 2 | |
maclobdell | 0:49e04b14e729 | 3 | DigitalOut red(LED_RED); // we create a variable 'red', use it as an out port |
maclobdell | 0:49e04b14e729 | 4 | DigitalOut green(LED_GREEN); // we create a variable 'green', use it as an out port |
maclobdell | 0:49e04b14e729 | 5 | |
maclobdell | 0:49e04b14e729 | 6 | InterruptIn btn2(SW2); // we create a variable 'btn2', use it as an in port |
maclobdell | 0:49e04b14e729 | 7 | InterruptIn btn3(SW3); // we create a variable 'btn3', use it as an in port |
maclobdell | 0:49e04b14e729 | 8 | |
maclobdell | 0:49e04b14e729 | 9 | // YOUR CODE HERE |
maclobdell | 0:49e04b14e729 | 10 | |
maclobdell | 0:49e04b14e729 | 11 | // this code runs when the microcontroller starts up |
maclobdell | 0:49e04b14e729 | 12 | int main() { |
maclobdell | 0:49e04b14e729 | 13 | green = red = 1; // turn off green and red on startup (1=off, I know it's weird) |
maclobdell | 0:49e04b14e729 | 14 | |
maclobdell | 0:49e04b14e729 | 15 | btn2.fall(toggle_red); |
maclobdell | 0:49e04b14e729 | 16 | btn3.fall(toggle_green); |
maclobdell | 0:49e04b14e729 | 17 | |
maclobdell | 0:49e04b14e729 | 18 | // spin in a main loop. Wait for interrupts. |
maclobdell | 0:49e04b14e729 | 19 | while(1) {} |
maclobdell | 0:49e04b14e729 | 20 | } |