diff Button.cpp @ 2:b76b999b88c7 default tip

fix flank detection
author ark
date 2017-01-31 00:07 +0100
parents 284066a427c8
children
line wrap: on
line diff
--- a/Button.cpp	Wed Jan 25 23:12:16 2017 +0100
+++ b/Button.cpp	Tue Jan 31 00:07:28 2017 +0100
@@ -32,18 +32,17 @@
 void Button::update(unsigned long ms) {
     bool s = this->readState();
     // process state change
+    this->isPressed = false;
+    this->isReleased = false;
     if(this->isOn != s) {
         // if last state change is older than threshold, accept new state
         // change is not a bounce.
         if(ms - this->lastChangeMs >= Button::BOUNCE_THRESHOLD) {
+            this->isOn = s;
             this->isPressed = this->isOn;
             this->isReleased = !this->isOn;
-            this->isOn = s;
             this->lastChangeMs = ms;
         }
-    } else {
-        this->isPressed = false;
-        this->isReleased = false;
     }
 }