Interrupt

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jforde
Date:
Tue Jul 28 11:48:32 2020 +0000
Parent:
3:4e35f0d99e64
Commit message:
Interrupt

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
diff -r 4e35f0d99e64 -r eea9dac99196 main.cpp
--- a/main.cpp	Fri Feb 21 20:30:41 2014 +0000
+++ b/main.cpp	Tue Jul 28 11:48:32 2020 +0000
@@ -1,14 +1,22 @@
-#include "mbed.h"
+#include "mbed.h"                              //Preprocessor Directives 
+
+InterruptIn joystickcenter(p14);              // Declarations 
+InterruptIn button(p9);
+DigitalOut led(LED1);
+DigitalOut flash(LED4);
+
 
-DigitalOut myled(LED1);
-DigitalOut myled2(LED2);
-int main() {
-    while(1) {
-        myled = 1;
-        myled2 = 0;
-        wait(0.5);
-        myled = 0;
-        myled2 = 1;
-        wait(0.5);
+void flip() {
+    led = !led;                        // toggles the led when the joystick button is pressed
+}
+
+int main() {                           //instructions in main () function 
+    joystickcenter.rise(&flip);        // attach the function address to the rising edge
+    button.mode(PullUp);               // With this, no external pullup resistor needed
+    button.rise(&flip);                // attach the function address to the rising edge
+    while(1) {                         // wait around, interrupts will interrupt this!
+        flash = !flash;                // turns LED4 on if off, off if on
+        wait(0.25);                    // the instruction to wait for a quarter-second
     }
 }
+
diff -r 4e35f0d99e64 -r eea9dac99196 mbed.bld
--- a/mbed.bld	Fri Feb 21 20:30:41 2014 +0000
+++ b/mbed.bld	Tue Jul 28 11:48:32 2020 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/078e4b97a13e
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file