Control Surface pin-t-adl
MIDI Control Surface library for Arduino
Button.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7
8#include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
10
12
18class Button {
19 public:
27 Button() : pin(NO_PIN) {}
28
36 Button(pin_t pin);
39
41 void begin();
42
47 void invert();
48
50 enum State {
51 Pressed = 0b00,
52 Released = 0b11,
53 Falling = 0b10,
54 Rising = 0b01
55 };
56
84 State update();
85
93 State getState() const;
94
96 static FlashString_t getName(State state);
97
99 unsigned long previousBounceTime() const;
100
103 unsigned long stableTime(unsigned long now) const;
104
106 unsigned long stableTime() const;
107
116 static void
117 setDebounceTime(unsigned long debounceTime = BUTTON_DEBOUNCE_TIME);
118
124 static unsigned long getDebounceTime();
125
126 private:
128
131 : debounced(0b11), bouncing(true), prevInput(HIGH), invert(false),
132 prevBounceTime(0) {}
133 uint8_t debounced : 2;
134 bool bouncing : 1;
135 bool prevInput : 1;
136 bool invert : 1;
137 unsigned long prevBounceTime;
138 } state;
139
142 static unsigned long debounceTime;
143};
144
146
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
AH::function_traits< decltype(::digitalWrite)>::argument_t< 0 > ArduinoPin_t
constexpr PinStatus_t HIGH
std::remove_reference< decltype(*F(""))>::type * FlashString_t
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
Button(ArduinoPin_t pin)
Construct a new Button object.
Definition: Button.hpp:38
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:50
pin_t pin
Definition: Button.hpp:127
Button()
Construct a new Button object.
Definition: Button.hpp:27
static unsigned long debounceTime
Edit this in Settings.hpp.
Definition: Button.hpp:142
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:137
Type for storing pin numbers of Extended Input/Output elements.