mbed Workshops
/
Workshop-1-Example-5
A digital input monitoring implementation with an interrupt.
Diff: main.cpp
- Revision:
- 0:501aab314b48
diff -r 000000000000 -r 501aab314b48 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 26 16:26:06 2016 +0000 @@ -0,0 +1,17 @@ +#include "mbed.h" + +InterruptIn button(SW1); +DigitalOut led(LED1); +DigitalOut heartbeat(LED2); + +void toggle() { + led = !led; +} + +int main() { + button.rise(&toggle); // call toggle function on the rising edge + while(1) { // wait around, interrupts will interrupt this! + heartbeat= !heartbeat; + wait(0.25); + } +} \ No newline at end of file