diff --git a/src/Bounce2.h b/src/Bounce2.h index 7dea71e..1a4d7ee 100644 --- a/src/Bounce2.h +++ b/src/Bounce2.h @@ -74,6 +74,7 @@ private: inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;} inline void toggleStateFlag(const uint8_t flag) {state ^= flag;} inline bool getStateFlag(const uint8_t flag) const {return((state & flag) != 0);} + inline bool thresholdPassed(); public: /*! diff --git a/src/Debounce.cpp b/src/Debounce.cpp index c82af69..7da28bd 100644 --- a/src/Debounce.cpp +++ b/src/Debounce.cpp @@ -43,7 +43,7 @@ bool Debouncer::update(){ // Ignore everything if we are locked out - if(millis() - previous_millis >= interval_millis){ + if(thresholdPassed()){ bool currentState = readCurrentState(); @@ -85,7 +85,7 @@ bool Debouncer::update(){ * - DEBOUNCED_STATE */ - if(millis() - previous_millis >= interval_millis) + if(thresholdPassed()) changeState(); } @@ -136,7 +136,7 @@ bool Debouncer::update(){ previous_millis = millis(); toggleStateFlag(UNSTABLE_STATE); } else - if(millis() - previous_millis >= interval_millis){ + if(thresholdPassed()){ /* * We have passed the threshold time @@ -202,3 +202,8 @@ bool Debouncer::fell() const { return ! getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); } + + +inline bool Debouncer::thresholdPassed(){ + return millis() - previous_millis >= interval_millis; +} \ No newline at end of file