Example using LED and push button
Fork of mbed-os-example-mbed5-blinky by
Revision 42:ee570b89946e, committed 2017-10-12
- Comitter:
- bigg55
- Date:
- Thu Oct 12 04:56:34 2017 +0000
- Parent:
- 41:3f37e8ac5378
- Commit message:
- Example Interrupts;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jul 18 09:45:02 2017 +0100
+++ b/main.cpp Thu Oct 12 04:56:34 2017 +0000
@@ -1,12 +1,17 @@
#include "mbed.h"
-
-DigitalOut led1(LED1);
-
-// main() runs in its own thread in the OS
+
+InterruptIn enable(D0); //Button active LOW
+DigitalOut led(D1);
+DigitalOut flash(D2);
+void flip() {
+ led = !led;
+}
+
int main() {
- while (true) {
- led1 = !led1;
- wait(0.5);
+ enable.rise(&flip); // attach the address of the flip function to the rising edge
+ while(1) { // wait around, interrupts will interrupt this!
+ flash = !flash;
+ wait(5);
}
+
}
-
