Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ABounce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ void ABounce::rebounce(unsigned long interval)

int ABounce::update()
{
if ( debounce() ) {
unsigned long now = millis();
if ( debounce(now) ) {
rebounce(0);
return stateChanged = 1;
}

// We need to rebounce, so simulate a state change

if ( rebounce_millis && (millis() - previous_millis >= rebounce_millis) ) {
previous_millis = millis();
if ( rebounce_millis && (now - previous_millis >= rebounce_millis) ) {
previous_millis = now;
rebounce(0);
return stateChanged = 1;
}
Expand All @@ -82,12 +83,12 @@ int ABounce::read()


// Protected: debounces the pin
int ABounce::debounce() {
int ABounce::debounce(unsigned long now) {

uint8_t newState = getButton(analogRead(pin));
if (state != newState ) {
if (millis() - previous_millis >= interval_millis) {
previous_millis = millis();
if (now - previous_millis >= interval_millis) {
previous_millis = now;
state = newState;
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion ABounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ABounce
bool fallingEdge();

protected:
int debounce();
int debounce(unsigned long now);
int getButton(int buttonValue);
unsigned long previous_millis, interval_millis, rebounce_millis;
uint8_t state;
Expand Down