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

Dependencies:   mbed

Committer:
iamhuzhe
Date:
Thu Jul 22 02:33:32 2010 +0000
Revision:
0:caf032e2b330

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iamhuzhe 0:caf032e2b330 1 #include "mbed.h"
iamhuzhe 0:caf032e2b330 2
iamhuzhe 0:caf032e2b330 3 InterruptIn button(p8);
iamhuzhe 0:caf032e2b330 4 DigitalIn bb(p8);
iamhuzhe 0:caf032e2b330 5
iamhuzhe 0:caf032e2b330 6 DigitalOut led(LED4);
iamhuzhe 0:caf032e2b330 7 DigitalOut flash(LED3);
iamhuzhe 0:caf032e2b330 8 Timeout t1;
iamhuzhe 0:caf032e2b330 9 Timeout t2;
iamhuzhe 0:caf032e2b330 10
iamhuzhe 0:caf032e2b330 11 int b1;
iamhuzhe 0:caf032e2b330 12 int b2;
iamhuzhe 0:caf032e2b330 13 void flip_again() {
iamhuzhe 0:caf032e2b330 14 if (bb==1) {
iamhuzhe 0:caf032e2b330 15 led = 1;
iamhuzhe 0:caf032e2b330 16
iamhuzhe 0:caf032e2b330 17 }
iamhuzhe 0:caf032e2b330 18 b1 = 0;
iamhuzhe 0:caf032e2b330 19
iamhuzhe 0:caf032e2b330 20 }
iamhuzhe 0:caf032e2b330 21
iamhuzhe 0:caf032e2b330 22 void flip_again2() {
iamhuzhe 0:caf032e2b330 23
iamhuzhe 0:caf032e2b330 24 if (bb==0) {
iamhuzhe 0:caf032e2b330 25 led = 0;
iamhuzhe 0:caf032e2b330 26
iamhuzhe 0:caf032e2b330 27 }
iamhuzhe 0:caf032e2b330 28 b2 = 0;
iamhuzhe 0:caf032e2b330 29
iamhuzhe 0:caf032e2b330 30
iamhuzhe 0:caf032e2b330 31 }
iamhuzhe 0:caf032e2b330 32
iamhuzhe 0:caf032e2b330 33 void flip() {
iamhuzhe 0:caf032e2b330 34 if (b1 == 0) {
iamhuzhe 0:caf032e2b330 35 b1 = 1;
iamhuzhe 0:caf032e2b330 36 t1.attach_us(&flip_again,100);
iamhuzhe 0:caf032e2b330 37 }
iamhuzhe 0:caf032e2b330 38 }
iamhuzhe 0:caf032e2b330 39
iamhuzhe 0:caf032e2b330 40
iamhuzhe 0:caf032e2b330 41 void flip2() {
iamhuzhe 0:caf032e2b330 42 if (b2 == 0) {
iamhuzhe 0:caf032e2b330 43 b2 = 1;
iamhuzhe 0:caf032e2b330 44 t2.attach_us(&flip_again2,100);
iamhuzhe 0:caf032e2b330 45 }
iamhuzhe 0:caf032e2b330 46 }
iamhuzhe 0:caf032e2b330 47
iamhuzhe 0:caf032e2b330 48
iamhuzhe 0:caf032e2b330 49
iamhuzhe 0:caf032e2b330 50 int main() {
iamhuzhe 0:caf032e2b330 51
iamhuzhe 0:caf032e2b330 52 button.mode(PullDown);
iamhuzhe 0:caf032e2b330 53 button.rise(&flip); // attach the address of the flip function to the rising edge
iamhuzhe 0:caf032e2b330 54 button.fall(&flip2);
iamhuzhe 0:caf032e2b330 55 while (1) { // wait around, interrupts will interrupt this!
iamhuzhe 0:caf032e2b330 56 flash = !flash;
iamhuzhe 0:caf032e2b330 57
iamhuzhe 0:caf032e2b330 58 wait(1);
iamhuzhe 0:caf032e2b330 59 }
iamhuzhe 0:caf032e2b330 60 }