Ruben De Swaef
/
PGO6_VoteController_code
Votecontroller
Fork of PGO6_VoteController_template by
debounce_button.cpp@0:fd29cd85e75e, 2017-10-26 (annotated)
- Committer:
- jensdehoog
- Date:
- Thu Oct 26 07:33:07 2017 +0000
- Revision:
- 0:fd29cd85e75e
- Child:
- 1:34e76c0cbe5a
Added the template for the assignment of the Vote Controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jensdehoog | 0:fd29cd85e75e | 1 | #include "debounce_button.h" |
jensdehoog | 0:fd29cd85e75e | 2 | |
jensdehoog | 0:fd29cd85e75e | 3 | /** |
jensdehoog | 0:fd29cd85e75e | 4 | Some tips and tricks: |
jensdehoog | 0:fd29cd85e75e | 5 | - To use the built-in LED: |
jensdehoog | 0:fd29cd85e75e | 6 | DigitalOut led1(LED1); |
jensdehoog | 0:fd29cd85e75e | 7 | ... |
jensdehoog | 0:fd29cd85e75e | 8 | led1 = 1; |
jensdehoog | 0:fd29cd85e75e | 9 | - To delay the call of a function: |
jensdehoog | 0:fd29cd85e75e | 10 | Timeout someTimeout; |
jensdehoog | 0:fd29cd85e75e | 11 | ... |
jensdehoog | 0:fd29cd85e75e | 12 | someTimeout.attach(callback(&someFunction), 0.5) with 0.5 as 500 milliseconds |
jensdehoog | 0:fd29cd85e75e | 13 | - The variables that are used in interrupt callbacks have to be volatile, |
jensdehoog | 0:fd29cd85e75e | 14 | because these variables can change at any time. Therefore, the compiler is not |
jensdehoog | 0:fd29cd85e75e | 15 | going to make optimisations. |
jensdehoog | 0:fd29cd85e75e | 16 | */ |
jensdehoog | 0:fd29cd85e75e | 17 | |
jensdehoog | 0:fd29cd85e75e | 18 | /** |
jensdehoog | 0:fd29cd85e75e | 19 | TODO |
jensdehoog | 0:fd29cd85e75e | 20 | ---- |
jensdehoog | 0:fd29cd85e75e | 21 | This function: |
jensdehoog | 0:fd29cd85e75e | 22 | - stores the amount of clicks in a variable which is read by the main loop. |
jensdehoog | 0:fd29cd85e75e | 23 | - resets the click counter which is used inside this file. |
jensdehoog | 0:fd29cd85e75e | 24 | - lowers a flag which tells the main loop that the user stopped pressing the button |
jensdehoog | 0:fd29cd85e75e | 25 | such that it can proceed its program. |
jensdehoog | 0:fd29cd85e75e | 26 | - turns the built-in LED off. Therefore, the user gets informed that the program stopped counting the clicks. |
jensdehoog | 0:fd29cd85e75e | 27 | */ |
jensdehoog | 0:fd29cd85e75e | 28 | void button1_multiclick_reset_cb(void) { |
jensdehoog | 0:fd29cd85e75e | 29 | |
jensdehoog | 0:fd29cd85e75e | 30 | } |
jensdehoog | 0:fd29cd85e75e | 31 | |
jensdehoog | 0:fd29cd85e75e | 32 | /** |
jensdehoog | 0:fd29cd85e75e | 33 | TODO |
jensdehoog | 0:fd29cd85e75e | 34 | ---- |
jensdehoog | 0:fd29cd85e75e | 35 | This function enables the button again, such that unwanted clicks of the bouncing button get ignored. |
jensdehoog | 0:fd29cd85e75e | 36 | */ |
jensdehoog | 0:fd29cd85e75e | 37 | void button1_enabled_cb(void) |
jensdehoog | 0:fd29cd85e75e | 38 | { |
jensdehoog | 0:fd29cd85e75e | 39 | |
jensdehoog | 0:fd29cd85e75e | 40 | } |
jensdehoog | 0:fd29cd85e75e | 41 | |
jensdehoog | 0:fd29cd85e75e | 42 | /** |
jensdehoog | 0:fd29cd85e75e | 43 | TODO |
jensdehoog | 0:fd29cd85e75e | 44 | ---- |
jensdehoog | 0:fd29cd85e75e | 45 | This function: |
jensdehoog | 0:fd29cd85e75e | 46 | - turns the built-in LED on, so the user gets informed that the program has started with counting clicks |
jensdehoog | 0:fd29cd85e75e | 47 | - disables the button such that the debouncer is active |
jensdehoog | 0:fd29cd85e75e | 48 | - enables the button again after a certain amount of time |
jensdehoog | 0:fd29cd85e75e | 49 | (use interrupts with "button1_enabled_cb()" as callback. |
jensdehoog | 0:fd29cd85e75e | 50 | - counts the amount of clicks within a period of 1 second |
jensdehoog | 0:fd29cd85e75e | 51 | - informs the main loop that the button has been pressed |
jensdehoog | 0:fd29cd85e75e | 52 | - informs the main loop that the user is clicking the button. |
jensdehoog | 0:fd29cd85e75e | 53 | Therefore, this main loop cannot continue its procedure until the clicks within 1 second have been counted. |
jensdehoog | 0:fd29cd85e75e | 54 | */ |
jensdehoog | 0:fd29cd85e75e | 55 | void button1_onpressed_cb(void) |
jensdehoog | 0:fd29cd85e75e | 56 | { |
jensdehoog | 0:fd29cd85e75e | 57 | |
jensdehoog | 0:fd29cd85e75e | 58 | } |