Control Surface
2.1.2
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
AH
Hardware
Button.hpp
Go to the documentation of this file.
1
/* ✔ */
2
3
#pragma once
4
5
#include <
AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp
>
6
#include <
AH/Settings/SettingsWrapper.hpp
>
7
8
BEGIN_AH_NAMESPACE
9
15
class
Button
{
16
public
:
24
Button
() :
pin
(
NO_PIN
) {}
25
33
Button
(
pin_t
pin);
35
Button
(
ArduinoPin_t
pin
) :
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
:
124
pin_t
pin
;
125
126
struct
InternalState
{
127
InternalState
()
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
142
END_AH_NAMESPACE
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition
AH/Settings/NamespaceSettings.hpp:14
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition
AH/Settings/NamespaceSettings.hpp:11
SettingsWrapper.hpp
HIGH
constexpr PinStatus_t HIGH
Definition
Arduino-Hardware-Types.hpp:62
ArduinoPin_t
AH::function_traits< decltype(::digitalWrite)>::argument_t< 0 > ArduinoPin_t
Definition
Arduino-Hardware-Types.hpp:23
FlashString_t
std::remove_reference< decltype(*F(""))>::type * FlashString_t
Definition
Arduino-Wrapper.h:18
ExtendedInputOutput.hpp
::Button
A class for reading and debouncing buttons and switches.
Definition
Button.hpp:15
AH::Button::Button
Button(ArduinoPin_t pin)
Construct a new Button object.
Definition
Button.hpp:35
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition
Button.hpp:47
AH::Button::Pressed
@ Pressed
Input went from low to low (0,0).
Definition
Button.hpp:48
AH::Button::Rising
@ Rising
Input went from low to high (0,1).
Definition
Button.hpp:51
AH::Button::Falling
@ Falling
Input went from high to low (1,0).
Definition
Button.hpp:50
AH::Button::Released
@ Released
Input went from high to high (1,1).
Definition
Button.hpp:49
AH::Button::pin
pin_t pin
Definition
Button.hpp:124
AH::Button::Button
Button()
Construct a new Button object.
Definition
Button.hpp:24
AH::Button::debounceTime
static unsigned long debounceTime
Edit this in Settings.hpp.
Definition
Button.hpp:139
AH::NO_PIN
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
Definition
Hardware-Types.hpp:96
AH::BUTTON_DEBOUNCE_TIME
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
Definition
AH/Settings/Settings.hpp:76
AH::Button::InternalState::invert
bool invert
Definition
Button.hpp:133
AH::Button::InternalState::InternalState
InternalState()
Definition
Button.hpp:127
AH::Button::InternalState::debounced
uint8_t debounced
Definition
Button.hpp:130
AH::Button::InternalState::bouncing
bool bouncing
Definition
Button.hpp:131
AH::Button::InternalState::prevInput
bool prevInput
Definition
Button.hpp:132
AH::Button::InternalState::prevBounceTime
unsigned long prevBounceTime
Definition
Button.hpp:134
AH::ExtIO::pin_t
Type for storing pin numbers of Extended Input/Output elements.
Definition
Hardware-Types.hpp:25
Generated by
1.17.0