33 #if defined(ARDUINO) && ARDUINO >= 100
66 static const uint8_t DEBOUNCED_STATE = 0b00000001;
67 static const uint8_t UNSTABLE_STATE = 0b00000010;
68 static const uint8_t CHANGED_STATE = 0b00000100;
72 inline void changeState();
73 inline void setStateFlag(
const uint8_t flag) {state |= flag;}
74 inline void unsetStateFlag(
const uint8_t flag) {state &= ~flag;}
75 inline void toggleStateFlag(
const uint8_t flag) {state ^= flag;}
76 inline bool getStateFlag(
const uint8_t flag)
const {
return((state & flag) != 0);}
93 void interval(uint16_t interval_millis);
130 bool changed( )
const {
return getStateFlag(CHANGED_STATE); }
170 virtual bool readCurrentState() =0;
171 unsigned long previous_millis;
172 uint16_t interval_millis;
174 unsigned long stateChangeLastTime;
175 unsigned long durationOfPreviousState;
257 virtual bool readCurrentState() {
return digitalRead(
pin); }
258 virtual void setPinMode(
int pin,
int mode) {
259 #if defined(ARDUINO_ARCH_STM32F1)
260 pinMode(
pin, (WiringPinMode)mode);
278 bool stateForPressed = 1;
300 stateForPressed = state;
307 return stateForPressed;
void interval(uint16_t interval_millis)
Sets the debounce interval in milliseconds.
Definition: Bounce2.cpp:14
unsigned long previousDuration() const
Returns the duration in milliseconds of the previous state.
Definition: Bounce2.cpp:103
Bounce()
Create an instance of the Bounce class.
Definition: Bounce2.cpp:138
unsigned long duration()
DEPRECATED (i.e. do not use). Renamed currentDuration().
Definition: Bounce2.h:164
bool fallingEdge() const
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:246
bool rose() const
Returns true if pin signal transitions from low to high.
Definition: Bounce2.cpp:123
uint8_t pin
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:255
unsigned long currentDuration() const
Returns the duration in milliseconds of the current state.
Definition: Bounce2.cpp:107
bool update()
Updates the pin's state.
Definition: Bounce2.cpp:32
The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named,...
Definition: Bounce2.h:184
int getPin() const
Return pin that this Bounce is attached to.
Definition: Bounce2.h:229
The Debouce class. Just the deboucing code separated from all harware.
Definition: Bounce2.h:62
bool fell() const
Returns true if pin signal transitions from high to low.
Definition: Bounce2.cpp:128
void attach(int pin, int mode)
Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT).
Definition: Bounce2.cpp:149
bool read() const
Returns the pin's state (HIGH or LOW).
Definition: Bounce2.cpp:118
bool risingEdge() const
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:241
bool changed() const
Returns true if the state changed on last update.
Definition: Bounce2.h:130
The Debouncer:Bounce:Button class. The Button class matches an electrical state to a physical action.
Definition: Bounce2.h:273
Debouncer()
Create an instance of the Debounce class.
Definition: Bounce2.cpp:10