Et eksempel på Debounce av en knapp ved hjelp av interrupts
Dependencies: mbed
Revision 0:95812c6efbce, committed 2015-11-05
- Comitter:
- benrammok
- Date:
- Thu Nov 05 13:14:36 2015 +0000
- Commit message:
- Debounce Program
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 95812c6efbce main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 05 13:14:36 2015 +0000 @@ -0,0 +1,45 @@ +#include "mbed.h" + +//Definerer inn/utganger +DigitalOut led(LED1); +InterruptIn button(USER_BUTTON); +Timeout tOut; + + +//Funksjonsprototyper +void btnClick(void); +void enableIRQ(void); +void toggleLed(void); + + +int main() { + //Setter pull-up og fester en funksjon til fall på button. + button.mode(PullUp); + button.fall(&btnClick); + + + + while(1) { + + wait(0.2); // 200 ms + } +} + +//Toggler Led fra av/på -> på/av +void toggleLed(){ + led = !led; //Toggler LED +} + + +//Skrur på interrupts +void enableIRQ(){ + button.enable_irq(); +} + + +//Kjører når knappen blir trykket +void btnClick(){ + button.disable_irq(); + tOut.attach_us(enableIRQ, 10); + toggleLed(); + } \ No newline at end of file
diff -r 000000000000 -r 95812c6efbce mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 05 13:14:36 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file