Dieter Balemans
/
PGO6_VoteController_Dieter_Balemans
VoteController
Fork of PGO6_VoteController_template by
Diff: debounce_button.cpp
- Revision:
- 3:6b6cab4ad185
- Parent:
- 2:5b7d055dbc91
--- a/debounce_button.cpp Tue Oct 31 09:01:56 2017 +0000 +++ b/debounce_button.cpp Thu Oct 11 15:58:11 2018 +0000 @@ -15,6 +15,15 @@ going to make optimisations. */ +volatile int counter = 0; +volatile int multiclick_state = false; +volatile bool button1_pressed = false; +volatile bool button1_busy = false; +volatile bool button1_enabled = true; +DigitalOut led1(LED1); +Timeout debouncer; +Timeout busy; + /** TODO ---- @@ -26,7 +35,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 = counter; + counter = 0; + button1_busy = false; + led1 = false; } /** @@ -36,7 +48,7 @@ */ void button1_enabled_cb(void) { - + button1_enabled = true; } /** @@ -54,5 +66,16 @@ */ void button1_onpressed_cb(void) { - + if(button1_enabled){ + button1_enabled = false; + button1_pressed = true; + debouncer.attach(callback(&button1_enabled_cb), 0.2); //Debounce 0.2s + if(button1_busy != true){ + led1 = true; + button1_busy = true; + busy.attach(callback(&button1_multiclick_reset_cb), 1); + } + counter++; + } + } \ No newline at end of file