11void Button::invert() { state.invert =
true; }
16 unsigned long now = millis();
19 state.bouncing = now - state.prevBounceTime <= debounceTime;
22 bool prevState = state.debounced & 0b01;
23 bool newState = state.bouncing ? prevState : input;
24 state.debounced = (prevState << 1) | newState;
26 if (input != state.prevInput) {
27 state.bouncing =
true;
28 state.prevInput = input;
29 state.prevBounceTime = now;
35 return static_cast<State>(state.debounced);
40 case Button::Pressed:
return F(
"Pressed");
41 case Button::Released:
return F(
"Released");
42 case Button::Falling:
return F(
"Falling");
43 case Button::Rising:
return F(
"Rising");
44 default:
return F(
"<invalid>");
48unsigned long Button::previousBounceTime()
const {
49 return state.prevBounceTime;
52unsigned long Button::stableTime(
unsigned long now)
const {
53 return now - previousBounceTime();
56unsigned long Button::stableTime()
const {
return stableTime(millis()); }
58void Button::setDebounceTime(
unsigned long debounceTime) {
59 Button::debounceTime = debounceTime;
62unsigned long Button::getDebounceTime() {
return Button::debounceTime; }
#define BEGIN_AH_NAMESPACE
constexpr PinMode_t INPUT_PULLUP
std::remove_reference< decltype(*F(""))>::type * FlashString_t
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
PinStatus_t digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
Type for storing pin numbers of Extended Input/Output elements.