PGO6

Dependencies:   MQTT

Revision:
3:14b20a4f36d0
Parent:
2:5b7d055dbc91
Child:
4:15e7cac255da
--- a/debounce_button.cpp	Tue Oct 31 09:01:56 2017 +0000
+++ b/debounce_button.cpp	Mon Oct 28 16:35:27 2019 +0000
@@ -27,6 +27,14 @@
 */
 void button1_multiclick_reset_cb(void) {
     
+    button_count = multiclick_state;
+    multiclick_state =0;
+    
+    button1_busy = false;
+    button1_pressed = false; 
+    
+    DigitalOut led1(LED1);
+    led1 = 0;
 }
 
 /**
@@ -36,7 +44,7 @@
 */
 void button1_enabled_cb(void)
 {
-    
+    button1_enabled = true;
 }
 
 /**
@@ -54,5 +62,25 @@
 */
 void button1_onpressed_cb(void)
 {
+    Timeout someTimeout;
+    // Turn led on
+    DigitalOut led1(LED1);
+    led1 = 1;
+    // Set button disabled
+    if(button1_enabled){
+        multiclick_state++;
+        button1_enabled = false;
+        someTimeout.attach(callback(&button1_enabled_cb), 0.1);
+    }
     
+    
+    // Inform main loop that user is clicking the button
+    button1_busy = true;
+    // Do a count after 1 second
+    if(button1_pressed == false){
+        // Inform main loop that button has been pressed
+        button1_pressed = true; 
+        someTimeout.attach(callback(&button1_multiclick_reset_cb), 1.0);
+    }
+   
 }
\ No newline at end of file