Reinout nvt
/
PGO6_VoteController_template
Initial commit
Fork of PGO6_VoteController_template by
Diff: debounce_button.cpp
- Revision:
- 1:e7a311bd038e
- Parent:
- 0:fd29cd85e75e
- Child:
- 2:f283e5274a0f
--- a/debounce_button.cpp Thu Oct 26 07:33:07 2017 +0000 +++ b/debounce_button.cpp Thu Oct 26 14:16:10 2017 +0000 @@ -1,4 +1,12 @@ #include "debounce_button.h" +volatile bool button1_pressed; // Used in the main loop +volatile bool button1_enabled=true; // Used for debouncing +volatile int multiclick_state; // Counts how many clicks occured in the time slot, used in main loop +volatile bool button1_busy=false; +Timeout enableTimeout; +Timeout resetTimeout; +DigitalOut myled(LED1); +int counter=0; /** Some tips and tricks: @@ -26,33 +34,49 @@ - turns the built-in LED off. Therefore, the user gets informed that the program stopped counting the clicks. */ void button1_multiclick_reset_cb(void) { - + myled=0; + multiclick_state=counter; + counter=0; + button1_busy=false; } /** - TODO + TODO:FINIDO ---- This function enables the button again, such that unwanted clicks of the bouncing button get ignored. */ void button1_enabled_cb(void) { - + button1_enabled=true; } + /** TODO ---- This function: - - turns the built-in LED on, so the user gets informed that the program has started with counting clicks - - disables the button such that the debouncer is active - - enables the button again after a certain amount of time + X- turns the built-in LED on, so the user gets informed that the program has started with counting clicks + X- disables the button such that the debouncer is active + X- enables the button again after a certain amount of time (use interrupts with "button1_enabled_cb()" as callback. - counts the amount of clicks within a period of 1 second - - informs the main loop that the button has been pressed + X- informs the main loop that the button has been pressed - informs the main loop that the user is clicking the button. Therefore, this main loop cannot continue its procedure until the clicks within 1 second have been counted. */ void button1_onpressed_cb(void) { - -} \ No newline at end of file + if(!button1_busy){ + button1_busy=true; + button1_enabled=false; + myled=1; + resetTimeout.attach(callback(&button1_multiclick_reset_cb), 1.0); + enableTimeout.attach(callback(&button1_enabled_cb), 0.1); + + } + if(button1_busy && button1_enabled){ + button1_enabled=false; + enableTimeout.attach(callback(&button1_enabled_cb), 0.1); + counter++; + } +}