Jack Occleshaw
/
w2-interrupt
w2interrupt
Diff: main.cpp
- Revision:
- 0:8dc791260768
diff -r 000000000000 -r 8dc791260768 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 12 15:42:21 2017 +0000 @@ -0,0 +1,18 @@ +/* External input causes interrupt, while led flashes*/ +#include "mbed.h" +InterruptIn button(SW2); //define and name the interrupt input +DigitalOut led(LED1); //red led defined as "led" +DigitalOut flash(LED2); //green led defined as "flash" + +void ISR1() { //this is the response to interrupt, i.e. the ISR + led = !led; +} +int main() { + button.rise(&ISR1); // attach the address of the ISR function to the +// interrupt rising edge + + while(1) { // continuous loop, ready to be interrupted + flash = !flash; // green led flashes + wait(0.25); // with time interval of 0.25s + } +}