w2interrupt

Dependencies:   mbed

Committer:
occle
Date:
Thu Jan 12 15:42:21 2017 +0000
Revision:
0:8dc791260768
w2interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
occle 0:8dc791260768 1 /* External input causes interrupt, while led flashes*/
occle 0:8dc791260768 2 #include "mbed.h"
occle 0:8dc791260768 3 InterruptIn button(SW2); //define and name the interrupt input
occle 0:8dc791260768 4 DigitalOut led(LED1); //red led defined as "led"
occle 0:8dc791260768 5 DigitalOut flash(LED2); //green led defined as "flash"
occle 0:8dc791260768 6
occle 0:8dc791260768 7 void ISR1() { //this is the response to interrupt, i.e. the ISR
occle 0:8dc791260768 8 led = !led;
occle 0:8dc791260768 9 }
occle 0:8dc791260768 10 int main() {
occle 0:8dc791260768 11 button.rise(&ISR1); // attach the address of the ISR function to the
occle 0:8dc791260768 12 // interrupt rising edge
occle 0:8dc791260768 13
occle 0:8dc791260768 14 while(1) { // continuous loop, ready to be interrupted
occle 0:8dc791260768 15 flash = !flash; // green led flashes
occle 0:8dc791260768 16 wait(0.25); // with time interval of 0.25s
occle 0:8dc791260768 17 }
occle 0:8dc791260768 18 }