This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Button.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
7 
9 
15 class Button {
16  public:
24  Button() : pin(NO_PIN) {}
25 
33  Button(pin_t pin);
34 
36  void begin();
37 
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 const __FlashStringHelper *getName(State state);
97 
99  unsigned long stableTime();
100 
101  private:
103 
104  bool prevInput = HIGH;
106  unsigned long prevBounceTime = 0;
107 
108 #ifdef INDIVIDUAL_BUTTON_INVERT // Edit this in Settings/Settings.hpp
109  bool invertState = false;
110 #else
111  static bool invertState;
112 #endif
113 
116  constexpr static unsigned long debounceTime = BUTTON_DEBOUNCE_TIME;
117 };
118 
Button::Rising
< Input went from high to low (1,0)
Definition: Button.hpp:54
Button::invert
INDIVIDUAL_BUTTON_INVERT_STATIC void invert()
Invert the state of all buttons, or of this specific button (button pressed is HIGH instead of LOW).
Definition: Button.cpp:11
Button::Falling
< Input went from high to high (1,1)
Definition: Button.hpp:53
Button::debouncedState
State debouncedState
Definition: Button.hpp:105
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:15
Button::pin
pin_t pin
Definition: Button.hpp:102
ExtendedInputOutput.hpp
BUTTON_DEBOUNCE_TIME
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
Definition: Settings.hpp:72
Button::prevBounceTime
unsigned long prevBounceTime
Definition: Button.hpp:106
Button::stableTime
unsigned long stableTime()
Return the time (in milliseconds) that the button has been stable for.
Definition: Button.cpp:46
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:34
Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:17
Button::prevInput
bool prevInput
Definition: Button.hpp:104
Button::getState
State getState() const
Get the state of the button, without updating it.
Definition: Button.cpp:34
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
INDIVIDUAL_BUTTON_INVERT_STATIC
#define INDIVIDUAL_BUTTON_INVERT_STATIC
Definition: SettingsWrapper.hpp:22
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:9
Button::debounceTime
constexpr static unsigned long debounceTime
Edit this in Settings.hpp.
Definition: Button.hpp:116
Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:50
Button::Button
Button()
Construct a new Button object.
Definition: Button.hpp:24
SettingsWrapper.hpp
NO_PIN
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
Definition: Def.hpp:24
Button::Pressed
Definition: Button.hpp:51
Button::getName
static const __FlashStringHelper * getName(State state)
Return the name of the state as a string.
Definition: Button.cpp:36
Button::Released
< Input went from low to low (0,0)
Definition: Button.hpp:52
Button::invertState
static bool invertState
Definition: Button.hpp:111