Ruben De Swaef
/
PGO6_VoteController_code
Votecontroller
Fork of PGO6_VoteController_template by
Diff: debounce_button.cpp
- Revision:
- 3:793425387c91
- Parent:
- 2:5b7d055dbc91
- Child:
- 4:bb892177ce23
diff -r 5b7d055dbc91 -r 793425387c91 debounce_button.cpp --- a/debounce_button.cpp Tue Oct 31 09:01:56 2017 +0000 +++ b/debounce_button.cpp Mon Oct 15 14:30:31 2018 +0000 @@ -1,5 +1,13 @@ #include "debounce_button.h" +DigitalOut led1(LED1); +volatile bool button1_busy = false; +volatile bool button1_enabled = true; +volatile int multiclick_state; +int clicks = 0; +Timeout clickResetTimeout; +Timeout btnEnableTimeout; + /** Some tips and tricks: - To use the built-in LED: @@ -26,7 +34,10 @@ - turns the built-in LED off. Therefore, the user gets informed that the program stopped counting the clicks. */ void button1_multiclick_reset_cb(void) { - + multiclick_state = clicks; + clicks = 0; + button1_busy = false; + led1 = 0; } /** @@ -36,7 +47,7 @@ */ void button1_enabled_cb(void) { - + button1_enabled = true; } /** @@ -54,5 +65,16 @@ */ void button1_onpressed_cb(void) { + printf("brn"); + if(!button1_busy){ // start clicking + led1 = 1; + button1_busy=true; + clickResetTimeout.attach(callback(&button1_multiclick_reset_cb), 1); //during 1 sec + } + if(button1_enabled){ + clicks++; + button1_enabled = false; + btnEnableTimeout.attach(callback(&button1_enabled_cb), 0.1); //debounce button + } } \ No newline at end of file