Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Button.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
7
9
15class Button {
16 public:
24 Button() : pin(NO_PIN) {}
25
33 Button(pin_t pin);
34
36 void begin();
37
42 void invert();
43
45 enum State {
46 Pressed = 0b00,
47 Released = 0b11,
48 Falling = 0b10,
49 Rising = 0b01
50 };
51
79 State update();
80
88 State getState() const;
89
91 static FlashString_t getName(State state);
92
94 unsigned long previousBounceTime() const;
95
98 unsigned long stableTime(unsigned long now) const;
99
101 unsigned long stableTime() const;
102
111 static void
112 setDebounceTime(unsigned long debounceTime = BUTTON_DEBOUNCE_TIME);
113
119 static unsigned long getDebounceTime();
120
121 private:
123
126 : debounced(0b11), bouncing(true), prevInput(HIGH), invert(false),
127 prevBounceTime(0) {}
129 bool bouncing : 1;
130 bool prevInput : 1;
131 bool invert : 1;
132 unsigned long prevBounceTime;
133 } state;
134
137 static unsigned long debounceTime;
138};
139
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
constexpr PinStatus_t HIGH
std::remove_reference< decltype(*F(""))>::type * FlashString_t
A class for reading and debouncing buttons and switches.
Definition Button.hpp:15
State
An enumeration of the different states a button can be in.
Definition Button.hpp:45
pin_t pin
Definition Button.hpp:122
Button()
Construct a new Button object.
Definition Button.hpp:24
static unsigned long debounceTime
Edit this in Settings.hpp.
Definition Button.hpp:137
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32
unsigned long prevBounceTime
Definition Button.hpp:132