interrupt trigger on both rising and falling edge (for level sensitive triggering)

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 InterruptIn button(p8);
00004 DigitalIn bb(p8);
00005 
00006 DigitalOut led(LED4);
00007 DigitalOut flash(LED3);
00008 Timeout t1;
00009 Timeout t2;
00010 
00011 int b1;
00012 int b2;
00013 void flip_again() {
00014     if (bb==1) {
00015         led = 1;
00016 
00017     }
00018     b1 = 0;
00019 
00020 }
00021 
00022 void flip_again2() {
00023 
00024     if (bb==0) {
00025         led = 0;
00026 
00027     }
00028     b2 = 0;
00029 
00030 
00031 }
00032 
00033 void flip() {
00034     if (b1 == 0) {
00035         b1 = 1;
00036         t1.attach_us(&flip_again,100);
00037     }
00038 }
00039 
00040 
00041 void flip2() {
00042     if (b2 == 0) {
00043         b2 = 1;
00044         t2.attach_us(&flip_again2,100);
00045     }
00046 }
00047 
00048 
00049 
00050 int main() {
00051 
00052     button.mode(PullDown);
00053     button.rise(&flip);  // attach the address of the flip function to the rising edge
00054     button.fall(&flip2);
00055     while (1) {          // wait around, interrupts will interrupt this!
00056         flash = !flash;
00057       
00058         wait(1);
00059     }
00060 }