execute a function when a button is pressed

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
maclobdell
Date:
Mon May 09 19:49:13 2016 +0000
Commit message:
initial version - modified from https://github.com/janjongboom/sxsw

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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) {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 09 19:49:13 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb
\ No newline at end of file