Control Surface  1.2.0
MIDI Control Surface library for Arduino
Button.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7 
8 #include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
10 
12 
18 class Button {
19  public:
27  Button() : pin(NO_PIN) {}
28 
36  Button(pin_t pin);
37 
39  void begin();
40 
51 
53  enum State {
54  Pressed = 0b00,
55  Released = 0b11,
56  Falling = 0b10,
57  Rising = 0b01
58  };
59 
87  State update();
88 
96  State getState() const;
97 
99  static FlashString_t getName(State state);
100 
102  unsigned long previousBounceTime() const;
103 
106  unsigned long stableTime(unsigned long now) const;
107 
109  unsigned long stableTime() const;
110 
119  static void
120  setDebounceTime(unsigned long debounceTime = BUTTON_DEBOUNCE_TIME);
121 
127  static unsigned long getDebounceTime();
128 
129  private:
131 
132  bool prevInput = HIGH;
133  State debouncedState = Released;
134  unsigned long prevBounceTime = 0;
135 
136 #ifdef AH_INDIVIDUAL_BUTTON_INVERT // Edit this in AH/Settings/Settings.hpp
137  bool invertState = false;
138 #else
139  static bool invertState;
140 #endif
141 
144  static unsigned long debounceTime;
145 };
146 
148 
AH::Button::pin
pin_t pin
Definition: Button.hpp:130
Warnings.hpp
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
AH::Button::debounceTime
static unsigned long debounceTime
Edit this in Settings.hpp.
Definition: Button.hpp:144
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
SettingsWrapper.hpp
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
AH_INDIVIDUAL_BUTTON_INVERT_STATIC
#define AH_INDIVIDUAL_BUTTON_INVERT_STATIC
Definition: AH/Settings/SettingsWrapper.hpp:29
HIGH
const PinStatus_t HIGH
Definition: ExtendedInputOutput.hpp:56
AH::BUTTON_DEBOUNCE_TIME
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
Definition: AH/Settings/Settings.hpp:74
FlashString_t
std::remove_reference< decltype(*F(""))>::type * FlashString_t
Definition: Arduino-Wrapper.h:18
AH::NO_PIN
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
Definition: Hardware-Types.hpp:24
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
AH::Button::Button
Button()
Construct a new Button object.
Definition: Button.hpp:27
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10