The three debounce methods available with Bounce2 are in the .cpp file in the .update method.
bool Bounce::update()
{
#ifdef BOUNCE_LOCK_OUT
state &= ~_BV(STATE_CHANGED);
// Ignore everything if we are locked out
if (millis() - previous_millis >= interval_millis) {
bool currentState = digitalRead(pin);
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
previous_millis = millis();
state ^= _BV(DEBOUNCED_STATE);
state |= _BV(STATE_CHANGED);
}
}
return state & _BV(STATE_CHANGED);
#elif defined BOUNCE_WITH_PROMPT_DETECTION
// Read the state of the switch port into a temporary variable.
bool readState = digitalRead(pin);
// Clear Changed State Flag - will be reset if we confirm a button state change.
state &= ~_BV(STATE_CHANGED);
if ( readState != (bool)(state & _BV(DEBOUNCED_STATE))) {
// We have seen a change from the current button state.
if ( millis() - previous_millis >= interval_millis ) {
// We have passed the time threshold, so a new change of state is allowed.
// set the STATE_CHANGED flag and the new DEBOUNCED_STATE.
// This will be prompt as long as there has been greater than interval_misllis ms since last change of input.
// Otherwise debounced state will not change again until bouncing is stable for the timeout period.
state ^= _BV(DEBOUNCED_STATE);
state |= _BV(STATE_CHANGED);
}
}
// If the readState is different from previous readState, reset the debounce timer - as input is still unstable
// and we want to prevent new button state changes until the previous one has remained stable for the timeout.
if ( readState != (bool)(state & _BV(UNSTABLE_STATE)) ) {
// Update Unstable Bit to macth readState
state ^= _BV(UNSTABLE_STATE);
previous_millis = millis();
}
// return just the sate changed bit
return state & _BV(STATE_CHANGED);
#else
// Read the state of the switch in a temporary variable.
bool currentState = digitalRead(pin);
state &= ~_BV(STATE_CHANGED);
// If the reading is different from last reading, reset the debounce counter
if ( currentState != (bool)(state & _BV(UNSTABLE_STATE)) ) {
previous_millis = millis();
state ^= _BV(UNSTABLE_STATE);
} else
if ( millis() - previous_millis >= interval_millis ) {
// We have passed the threshold time, so the input is now stable
// If it is different from last state, set the STATE_CHANGED flag
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
previous_millis = millis();
state ^= _BV(DEBOUNCED_STATE);
state |= _BV(STATE_CHANGED);
}
}
return state & _BV(STATE_CHANGED);
#endif
}
The way I understand the three methods
BOUNCE_LOCK_OUT
This method only allows a digital read at a timed interval from the last reading, and accepts the value.
BOUNCE_WITH_PROMPT_DETECTION
This method, take a digital reading when the method is called, but only accepts the value if the time is greater than the debounce interval from the previous reading.
Both these methods are "prompt", but can accept a false positive due to noise on the input.
DEFAULT
The default method requires the reading to be unchanged(stable) for the debounce interval interval. This method is noise resistant, but only accepts the value at the end of a timed interval.