Aleksander Chernyavskiy
/
pgo6_aleksander_chernyavskiy
opdracht mqtt nucleo
Fork of PGO6_VoteController_template by
debounce_button.cpp@1:34e76c0cbe5a, 2017-10-29 (annotated)
- Committer:
- jensdehoog
- Date:
- Sun Oct 29 23:01:06 2017 +0000
- Revision:
- 1:34e76c0cbe5a
- Parent:
- 0:fd29cd85e75e
- Child:
- 2:5b7d055dbc91
Updated the assignment for a longer during time
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 | 1:34e76c0cbe5a | 4 | TODO |
jensdehoog | 1:34e76c0cbe5a | 5 | ---- |
jensdehoog | 1:34e76c0cbe5a | 6 | - A debouncer has to be present: the built-in buttons of the Nucleo aren't that good, so false positives have to be filtered out. |
jensdehoog | 1:34e76c0cbe5a | 7 | Find a method such that false calls of this function are going to be filtered out. |
jensdehoog | 1:34e76c0cbe5a | 8 | The main loop also needs to know when it can process the further instructions. |
jensdehoog | 1:34e76c0cbe5a | 9 | An acceptable time to disable further false positives is between 50ms and 100ms. |
jensdehoog | 1:34e76c0cbe5a | 10 | - The user needs to be able to click the button multiple times in 1 second. |
jensdehoog | 1:34e76c0cbe5a | 11 | The main loop needs to know how many times the user has pressed the button, such that |
jensdehoog | 1:34e76c0cbe5a | 12 | it can link different procedures to the different multiclicks. The main loop also needs |
jensdehoog | 1:34e76c0cbe5a | 13 | to know when this function is counting the clicks. Therefore, it has to wait until the clicks have been counted |
jensdehoog | 1:34e76c0cbe5a | 14 | before it can proceed. |
jensdehoog | 1:34e76c0cbe5a | 15 | - LED1 needs to be turned on while the function is counting the amount of clicks within 1 second. |
jensdehoog | 1:34e76c0cbe5a | 16 | |
jensdehoog | 0:fd29cd85e75e | 17 | Some tips and tricks: |
jensdehoog | 0:fd29cd85e75e | 18 | - To use the built-in LED: |
jensdehoog | 0:fd29cd85e75e | 19 | DigitalOut led1(LED1); |
jensdehoog | 0:fd29cd85e75e | 20 | ... |
jensdehoog | 0:fd29cd85e75e | 21 | led1 = 1; |
jensdehoog | 0:fd29cd85e75e | 22 | - To delay the call of a function: |
jensdehoog | 0:fd29cd85e75e | 23 | Timeout someTimeout; |
jensdehoog | 0:fd29cd85e75e | 24 | ... |
jensdehoog | 1:34e76c0cbe5a | 25 | someTimeout.attach(callback(&anotherFunction), 0.5) with 0.5 as 500 milliseconds |
jensdehoog | 0:fd29cd85e75e | 26 | - The variables that are used in interrupt callbacks have to be volatile, |
jensdehoog | 0:fd29cd85e75e | 27 | because these variables can change at any time. Therefore, the compiler is not |
jensdehoog | 0:fd29cd85e75e | 28 | going to make optimisations. |
jensdehoog | 1:34e76c0cbe5a | 29 | - Use boolean flags to send information between different processes. |
jensdehoog | 1:34e76c0cbe5a | 30 | - In the header file are extra functions and variables that can help you developing these procedures. |
jensdehoog | 1:34e76c0cbe5a | 31 | You can add, change or remove these functions and variables at any time, as long as it is clear what you've done. |
jensdehoog | 0:fd29cd85e75e | 32 | */ |
jensdehoog | 0:fd29cd85e75e | 33 | |
jensdehoog | 0:fd29cd85e75e | 34 | /** |
jensdehoog | 1:34e76c0cbe5a | 35 | This function is called when the button has been pressed by the user. |
jensdehoog | 0:fd29cd85e75e | 36 | */ |
jensdehoog | 0:fd29cd85e75e | 37 | |
jensdehoog | 0:fd29cd85e75e | 38 | void button1_onpressed_cb(void) |
jensdehoog | 0:fd29cd85e75e | 39 | { |
jensdehoog | 0:fd29cd85e75e | 40 | |
jensdehoog | 0:fd29cd85e75e | 41 | } |