Rob Toulson / Mbed 2 deprecated PE_09-01_SimpleInterrupt

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Program Example 9.1: Simple interrupt example. External input causes interrupt, while led flashes  
00002                                                                             */
00003 #include "mbed.h"
00004 InterruptIn button(p5);    //define and name the interrupt input
00005 DigitalOut led(LED1);       
00006 DigitalOut flash(LED4);
00007 
00008 void ISR1() {                 //this is the response to interrupt, i.e. the ISR
00009   led = !led;
00010 }
00011 
00012 int main() {
00013   button.rise(&ISR1);     // attach the address of the ISR function to the                               
00014                                               // interrupt rising edge
00015   while(1) {              // continuous loop, ready to be interrupted
00016     flash = !flash;
00017     wait(0.25);
00018   }
00019 }
00020