State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Revision:
2:141cfcafe72b
Parent:
1:cfa5abca6d43
Child:
3:4b19b6cf6cc7
--- a/Button.h	Tue Oct 30 11:01:00 2018 +0000
+++ b/Button.h	Tue Oct 30 11:21:09 2018 +0000
@@ -43,12 +43,14 @@
     bool has_just_been_pressed() { return just_got_pressed; };
 private:
     void rise() {
-        debounce_timeout.attach(this, &Button::debounce_callback, debounce_time);
+        // Button is now potentially pressed, or is simply bouncing.
+        debounce_timeout.detach();
+        pressed = false;
     }
     
     void fall() {
-        debounce_timeout.detach();
-        pressed = false;
+        // Button just got released, or bounced up again.
+        debounce_timeout.attach(this, &Button::debounce_callback, debounce_time);
     }
     
     void debounce_callback() {