PushDuration maps n callback functions to the duration of a button press. E.g. foo() is called when a button is released after 1 second where bar() is called after 3 seconds.

Fork of PushDuration by Jens Strümper

Revision:
3:d2aec01c8227
Parent:
2:126fed923ada
--- a/PushDuration.cpp	Wed Aug 17 09:29:41 2016 +0000
+++ b/PushDuration.cpp	Sat Aug 20 18:58:48 2016 +0000
@@ -32,17 +32,18 @@
     ticker.detach();
 }
 
-void ButtonHandler::press() {
+void ButtonHandler::release() {
     counter = 0;
     ticker.attach(this, &ButtonHandler::secondsCount, intervalInSeconds);
 }
 
+void ButtonHandler::press() {
+    ticker.detach();
+    react(counter);
+    counter = 0;
+}
+
 void ButtonHandler::secondsCount() {
     ++counter;
+    printf("counter: %d\n", counter);
 }
-
-void ButtonHandler::release() {
-    ticker.detach();
-    react(counter);
-    counter = 0;
-}
\ No newline at end of file