Control Surface 2.1.2
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:
25
33 Button(pin_t pin);
36
38 void begin();
39
44 void invert();
45
47 enum State {
48 Pressed = 0b00,
49 Released = 0b11,
50 Falling = 0b10,
51 Rising = 0b01
52 };
53
81 State update();
82
90 State getState() const;
91
93 static FlashString_t getName(State state);
94
96 unsigned long previousBounceTime() const;
97
100 unsigned long stableTime(unsigned long now) const;
101
103 unsigned long stableTime() const;
104
113 static void
114 setDebounceTime(unsigned long debounceTime = BUTTON_DEBOUNCE_TIME);
115
121 static unsigned long getDebounceTime();
122
123 private:
125
128 : debounced(0b11), bouncing(true), prevInput(HIGH), invert(false),
129 prevBounceTime(0) {}
130 uint8_t debounced : 2;
131 bool bouncing : 1;
132 bool prevInput : 1;
133 bool invert : 1;
134 unsigned long prevBounceTime;
135 } state;
136
139 static unsigned long debounceTime;
140};
141
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
constexpr PinStatus_t HIGH
AH::function_traits< decltype(::digitalWrite)>::argument_t< 0 > ArduinoPin_t
std::remove_reference< decltype(*F(""))>::type * FlashString_t
A class for reading and debouncing buttons and switches.
Definition Button.hpp:15
Button(ArduinoPin_t pin)
Construct a new Button object.
Definition Button.hpp:35
State
An enumeration of the different states a button can be in.
Definition Button.hpp:47
@ Pressed
Input went from low to low (0,0).
Definition Button.hpp:48
@ Rising
Input went from low to high (0,1).
Definition Button.hpp:51
@ Falling
Input went from high to low (1,0).
Definition Button.hpp:50
@ Released
Input went from high to high (1,1).
Definition Button.hpp:49
pin_t pin
Definition Button.hpp:124
Button()
Construct a new Button object.
Definition Button.hpp:24
static unsigned long debounceTime
Edit this in Settings.hpp.
Definition Button.hpp:139
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
unsigned long prevBounceTime
Definition Button.hpp:134
Type for storing pin numbers of Extended Input/Output elements.