Skip to content

Commit

Permalink
Update ADebouncer.cpp
Browse files Browse the repository at this point in the history
Correct bitwise NOT (~) and use bitwise XOR (^) instead of not equal to (!=).
  • Loading branch information
MicroBeaut authored Dec 21, 2023
1 parent 9a53a51 commit 348b964
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ADebouncer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ boolean ADebouncer::debounce(boolean input) {
_prevInput = _input;
_prevOutput = _output;
_input = input;
if (_input != _prevInput) _debounceStartTime = currentTime;
if (_input ^ _prevInput) _debounceStartTime = currentTime;
if (_debouncing) {
unsigned long elapsedTime = currentTime - _debounceStartTime;
if (elapsedTime >= _debouncePeriod) {
_debouncing = false;
_output = _input;
}
} else {
if (_input != _output) {
if (_instant == INSTANT) _output = _input;
if (_input ^ _output) {
if (_instant) _output = _input;
_debouncing = true;
}
}
_rising = _output & !_prevOutput;
_falling = !_output & _prevOutput;
_rising = _output & ~_prevOutput;
_falling = ~_output & _prevOutput;
return _output;
}

Expand All @@ -62,4 +62,4 @@ boolean ADebouncer::rising() {

boolean ADebouncer::falling() {
return _falling;
}
}

0 comments on commit 348b964

Please sign in to comment.