# HG changeset patch # User ark # Date 1485817648 -3600 # Node ID b76b999b88c783d13e2002701aae9c7ff20fe4f9 # Parent 284066a427c887d6b8f4f11ac29452e230b601cc fix flank detection diff -r 284066a427c8 -r b76b999b88c7 Button.cpp --- 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; } } diff -r 284066a427c8 -r b76b999b88c7 Button.h --- a/Button.h Wed Jan 25 23:12:16 2017 +0100 +++ b/Button.h Tue Jan 31 00:07:28 2017 +0100 @@ -58,7 +58,7 @@ /** bounce threshold in miliseconds. state changes are ignored for that * long after a change. */ - const unsigned long BOUNCE_THRESHOLD = 100; + const unsigned long BOUNCE_THRESHOLD = 150; private: byte pin;