Vincent Nys

Dependencies:   MQTT

Fork of PGO6_VoteController_template by Jens de hoog

Revision:
3:c53f27bdcfb5
Parent:
2:5b7d055dbc91
--- a/debounce_button.cpp	Tue Oct 31 09:01:56 2017 +0000
+++ b/debounce_button.cpp	Tue Oct 31 18:31:34 2017 +0000
@@ -1,5 +1,10 @@
 #include "debounce_button.h"
 
+DigitalOut led1(LED1);
+volatile int click_counter = 0;
+Timeout multiclick;
+Timeout debounce;
+
 /**
     Some tips and tricks:
     -   To use the built-in LED:
@@ -25,8 +30,12 @@
             such that it can proceed its program.
         -   turns the built-in LED off. Therefore, the user gets informed that the program stopped counting the clicks.
 */
-void button1_multiclick_reset_cb(void) {
-    
+void button1_multiclick_reset_cb(void) 
+{
+    button1_busy = false;
+    multiclick_state = click_counter;
+    click_counter = 0;    
+    led1 = 0;
 }
 
 /**
@@ -36,7 +45,7 @@
 */
 void button1_enabled_cb(void)
 {
-    
+    button1_enabled = true;
 }
 
 /**
@@ -54,5 +63,16 @@
 */
 void button1_onpressed_cb(void)
 {
-    
+    if(!button1_busy)
+    {
+        multiclick.attach( &button1_multiclick_reset_cb, 1 );
+    }
+    button1_busy = true;
+    led1 = 1;
+    if( button1_enabled )
+    {
+        button1_enabled = false;
+        click_counter++;
+        debounce.attach( &button1_enabled_cb, 0.08 ); // 80ms   
+    }
 }
\ No newline at end of file