PGO6

Dependencies:   MQTT

Committer:
s0130594
Date:
Thu Nov 14 15:07:12 2019 +0100
Revision:
6:754d3e8f9ae9
Parent:
4:15e7cac255da
Added MQTT functionality

Who changed what in which revision?

UserRevisionLine numberNew 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 */
s0130594 4:15e7cac255da 28 /*void button1_multiclick_reset_cb(void) {
jensdehoog 2:5b7d055dbc91 29
s0130594 3:14b20a4f36d0 30 button_count = multiclick_state;
s0130594 3:14b20a4f36d0 31 multiclick_state =0;
s0130594 3:14b20a4f36d0 32
s0130594 3:14b20a4f36d0 33 button1_busy = false;
s0130594 3:14b20a4f36d0 34 button1_pressed = false;
s0130594 3:14b20a4f36d0 35
s0130594 3:14b20a4f36d0 36 DigitalOut led1(LED1);
s0130594 3:14b20a4f36d0 37 led1 = 0;
s0130594 4:15e7cac255da 38 }*/
jensdehoog 2:5b7d055dbc91 39
jensdehoog 2:5b7d055dbc91 40 /**
jensdehoog 2:5b7d055dbc91 41 TODO
jensdehoog 2:5b7d055dbc91 42 ----
jensdehoog 2:5b7d055dbc91 43 This function enables the button again, such that unwanted clicks of the bouncing button get ignored.
jensdehoog 0:fd29cd85e75e 44 */
s0130594 4:15e7cac255da 45 /*void button1_enabled_cb(void)
jensdehoog 2:5b7d055dbc91 46 {
s0130594 3:14b20a4f36d0 47 button1_enabled = true;
s0130594 4:15e7cac255da 48 }*/
jensdehoog 0:fd29cd85e75e 49
jensdehoog 2:5b7d055dbc91 50 /**
jensdehoog 2:5b7d055dbc91 51 TODO
jensdehoog 2:5b7d055dbc91 52 ----
jensdehoog 2:5b7d055dbc91 53 This function:
jensdehoog 2:5b7d055dbc91 54 - turns the built-in LED on, so the user gets informed that the program has started with counting clicks
jensdehoog 2:5b7d055dbc91 55 - disables the button such that the debouncer is active
jensdehoog 2:5b7d055dbc91 56 - enables the button again after a certain amount of time
jensdehoog 2:5b7d055dbc91 57 (use interrupts with "button1_enabled_cb()" as callback.
jensdehoog 2:5b7d055dbc91 58 - counts the amount of clicks within a period of 1 second
jensdehoog 2:5b7d055dbc91 59 - informs the main loop that the button has been pressed
jensdehoog 2:5b7d055dbc91 60 - informs the main loop that the user is clicking the button.
jensdehoog 2:5b7d055dbc91 61 Therefore, this main loop cannot continue its procedure until the clicks within 1 second have been counted.
jensdehoog 2:5b7d055dbc91 62 */
s0130594 4:15e7cac255da 63 /*void button1_onpressed_cb(void)
jensdehoog 0:fd29cd85e75e 64 {
s0130594 3:14b20a4f36d0 65 Timeout someTimeout;
s0130594 3:14b20a4f36d0 66 // Turn led on
s0130594 3:14b20a4f36d0 67 DigitalOut led1(LED1);
s0130594 3:14b20a4f36d0 68 led1 = 1;
s0130594 3:14b20a4f36d0 69 // Set button disabled
s0130594 3:14b20a4f36d0 70 if(button1_enabled){
s0130594 3:14b20a4f36d0 71 multiclick_state++;
s0130594 3:14b20a4f36d0 72 button1_enabled = false;
s0130594 3:14b20a4f36d0 73 someTimeout.attach(callback(&button1_enabled_cb), 0.1);
s0130594 3:14b20a4f36d0 74 }
jensdehoog 0:fd29cd85e75e 75
s0130594 3:14b20a4f36d0 76
s0130594 3:14b20a4f36d0 77 // Inform main loop that user is clicking the button
s0130594 3:14b20a4f36d0 78 button1_busy = true;
s0130594 3:14b20a4f36d0 79 // Do a count after 1 second
s0130594 3:14b20a4f36d0 80 if(button1_pressed == false){
s0130594 3:14b20a4f36d0 81 // Inform main loop that button has been pressed
s0130594 3:14b20a4f36d0 82 button1_pressed = true;
s0130594 3:14b20a4f36d0 83 someTimeout.attach(callback(&button1_multiclick_reset_cb), 1.0);
s0130594 3:14b20a4f36d0 84 }
s0130594 3:14b20a4f36d0 85
s0130594 4:15e7cac255da 86 }*/