wobblyhead hg > arduino > Button
changeset 2:b76b999b88c7 default tip
fix flank detection
| author | ark |
|---|---|
| date | 2017-01-31 00:07 +0100 |
| parents | 284066a427c8 |
| children | |
| files | Button.cpp Button.h |
| diffstat | 2 files changed, 4 insertions(+), 5 deletions(-) [+] |
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; } }
--- 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;
