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);
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) {}
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
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
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
unsigned long prevBounceTime
Definition Button.hpp:134
Type for storing pin numbers of Extended Input/Output elements.