Simple Debouncing library and sample code.
Dependencies: DebouncedIn mbed
Diff: main.cpp
- Revision:
- 1:3f6f29315707
- Parent:
- 0:4b63a4c5ed47
- Child:
- 2:e7f390d1e86c
--- a/main.cpp Sun Jun 05 13:12:33 2016 +0000 +++ b/main.cpp Sun Jun 12 09:17:20 2016 +0000 @@ -1,13 +1,20 @@ #include "mbed.h" #include "DebouncedIn.h" -DigitalOut led(PTA5); //red led +DigitalOut led(LED1); //red led DebouncedIn button(PTC9); //switch int main() { while(1) { - if (button.rising()){ //execute only if rising edge detected on the button. + //using library directly + /*if (button.rising()){ //execute only if rising edge detected on the button. led = !led; + }*/ + + //without library + if(button == 0) { //detecting press + led = !led; + while(button==0); //empty while to wait while switch is pressed. hence toggling only once. } } }