Rob Toulson / Mbed 2 deprecated PE_09-02_InterruptLatency

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Program Example 9.2: Tests interrupt latency. External input causes interrupt, which pulses external LED while LED4 flashes continuously.                                                                     
00002                                                                            */
00003 #include "mbed.h"
00004 InterruptIn squarewave(p5);     //Connect input square wave here
00005 DigitalOut led(p6);
00006 DigitalOut flash(LED4);
00007 
00008 void pulse() {                 //ISR sets external led high for fixed duration
00009   led = 1;
00010   wait(0.01);
00011   led = 0;
00012 }
00013 
00014 int main() {
00015   squarewave.rise(&pulse);  // attach the address of the pulse function to
00016                                                              // the rising edge
00017   while(1) {                // interrupt will occur within this endless loop
00018     flash = !flash;
00019     wait(0.25);
00020   }
00021 }
00022