PGO6_VoteController (Astrid Vanneste)

Dependencies:   MQTT

Fork of PGO6_VoteController_template by Jens de hoog

Revision:
5:ba94770ce1c7
Parent:
4:08da93eb6014
--- a/debounce_button.cpp	Mon Oct 08 13:37:19 2018 +0000
+++ b/debounce_button.cpp	Mon Oct 08 15:39:22 2018 +0000
@@ -6,6 +6,9 @@
 volatile bool button1_busy;              // Informs the mainloop that the user is clicking the button => busy multiclick
 volatile int internal_click_count;       // Counts how many clicks occured in the time slot
 
+Timeout debounce_time;
+Timeout multiclick_time;
+
 /**
     Some tips and tricks:
     -   To use the built-in LED:
@@ -33,13 +36,14 @@
 */
 void button1_multiclick_reset_cb(void) 
 {
-    printf("multiclick disable");
     button1_busy = false;
     multiclick_state = internal_click_count;
+    //printf("Clicks: %d\n", multiclick_state);
     internal_click_count = 0;
     
     DigitalOut led1(LED1);
     led1 = 0;
+    button1_pressed = true;
 }
 
 /**
@@ -66,26 +70,22 @@
             Therefore, this main loop cannot continue its procedure until the clicks within 1 second have been counted.
 */
 void button1_onpressed_cb(void)
-{
-    DigitalOut led1(LED1);
-    led1 = 1;
-    
+{   
     if(button1_enabled)
     {
+        DigitalOut led1(LED1);
+        led1 = 1;
         button1_enabled = false;        // button is not enabled => debouncing
         
-        Timeout debounce_time;
-        debounce_time.attach(callback(button1_enabled_cb), 0.5);
+        debounce_time.attach(callback(&button1_enabled_cb), 0.1);
         
         internal_click_count++;
         
         if(!button1_busy)
         {
-            button1_pressed = true;
             button1_busy = true;
             
-            Timeout multiclick_time;
-            multiclick_time.attach(callback(button1_multiclick_reset_cb), 1);
+            multiclick_time.attach(callback(&button1_multiclick_reset_cb), 1);
         }
     }
 }
@@ -97,5 +97,4 @@
     button1_busy = false;
     multiclick_state = 0;
     internal_click_count = 0;
-    
 }
\ No newline at end of file