interrupt rising/falling edge test

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 BusOut leds( LED4, LED3, LED2, LED1 );
00004 char count;
00005 
00006 InterruptIn button( p16 );   //  interrupt instance for the button
00007 Timer t;               //  To manage debounce by menchanical switch
00008 
00009 #define DEBOUNCING_INTERVAL 20   //  Debouncing interval (in mili-seconds)
00010 
00011 void isr_buton( void ) {
00012     if ( t.read_ms() > DEBOUNCING_INTERVAL ) {
00013         leds    = (count++) & 0xF;
00014     }
00015     t.reset();  //  timer reset
00016 }
00017 
00018 void isr_button2(void) {
00019     if ( t.read_ms() > DEBOUNCING_INTERVAL ) {
00020         leds    = (count--) & 0xF;
00021     }
00022     t.reset();  //  timer reset
00023 }
00024 
00025 int main() {
00026     count   = 0;
00027     t.start();  //  timer start
00028     button.rise( &isr_buton );
00029     button.fall(&isr_button2);
00030     while ( 1 ) {
00031     }
00032 }