![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
opdracht mqtt nucleo
Fork of PGO6_VoteController_template by
debounce_button.cpp@2:5b7d055dbc91, 2017-10-31 (annotated)
- Committer:
- jensdehoog
- Date:
- Tue Oct 31 09:01:56 2017 +0000
- Revision:
- 2:5b7d055dbc91
- Parent:
- 1:34e76c0cbe5a
- Child:
- 3:abfa79c5b7bd
Reverted to the original assignment, which was made for a duration time of 4 hours
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 | 2:5b7d055dbc91 | 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 | 2:5b7d055dbc91 | 19 | TODO |
jensdehoog | 2:5b7d055dbc91 | 20 | ---- |
jensdehoog | 2:5b7d055dbc91 | 21 | This function: |
jensdehoog | 2:5b7d055dbc91 | 22 | - stores the amount of clicks in a variable which is read by the main loop. |
jensdehoog | 2:5b7d055dbc91 | 23 | - resets the click counter which is used inside this file. |
jensdehoog | 2:5b7d055dbc91 | 24 | - lowers a flag which tells the main loop that the user stopped pressing the button |
jensdehoog | 2:5b7d055dbc91 | 25 | such that it can proceed its program. |
jensdehoog | 2:5b7d055dbc91 | 26 | - turns the built-in LED off. Therefore, the user gets informed that the program stopped counting the clicks. |
jensdehoog | 2:5b7d055dbc91 | 27 | */ |
jensdehoog | 2:5b7d055dbc91 | 28 | void button1_multiclick_reset_cb(void) { |
jensdehoog | 2:5b7d055dbc91 | 29 | |
jensdehoog | 2:5b7d055dbc91 | 30 | } |
jensdehoog | 2:5b7d055dbc91 | 31 | |
jensdehoog | 2:5b7d055dbc91 | 32 | /** |
jensdehoog | 2:5b7d055dbc91 | 33 | TODO |
jensdehoog | 2:5b7d055dbc91 | 34 | ---- |
jensdehoog | 2:5b7d055dbc91 | 35 | This function enables the button again, such that unwanted clicks of the bouncing button get ignored. |
jensdehoog | 0:fd29cd85e75e | 36 | */ |
jensdehoog | 2:5b7d055dbc91 | 37 | void button1_enabled_cb(void) |
jensdehoog | 2:5b7d055dbc91 | 38 | { |
jensdehoog | 2:5b7d055dbc91 | 39 | |
jensdehoog | 2:5b7d055dbc91 | 40 | } |
jensdehoog | 0:fd29cd85e75e | 41 | |
jensdehoog | 2:5b7d055dbc91 | 42 | /** |
jensdehoog | 2:5b7d055dbc91 | 43 | TODO |
jensdehoog | 2:5b7d055dbc91 | 44 | ---- |
jensdehoog | 2:5b7d055dbc91 | 45 | This function: |
jensdehoog | 2:5b7d055dbc91 | 46 | - turns the built-in LED on, so the user gets informed that the program has started with counting clicks |
jensdehoog | 2:5b7d055dbc91 | 47 | - disables the button such that the debouncer is active |
jensdehoog | 2:5b7d055dbc91 | 48 | - enables the button again after a certain amount of time |
jensdehoog | 2:5b7d055dbc91 | 49 | (use interrupts with "button1_enabled_cb()" as callback. |
jensdehoog | 2:5b7d055dbc91 | 50 | - counts the amount of clicks within a period of 1 second |
jensdehoog | 2:5b7d055dbc91 | 51 | - informs the main loop that the button has been pressed |
jensdehoog | 2:5b7d055dbc91 | 52 | - informs the main loop that the user is clicking the button. |
jensdehoog | 2:5b7d055dbc91 | 53 | Therefore, this main loop cannot continue its procedure until the clicks within 1 second have been counted. |
jensdehoog | 2:5b7d055dbc91 | 54 | */ |
jensdehoog | 0:fd29cd85e75e | 55 | void button1_onpressed_cb(void) |
jensdehoog | 0:fd29cd85e75e | 56 | { |
jensdehoog | 0:fd29cd85e75e | 57 | |
jensdehoog | 0:fd29cd85e75e | 58 | } |