Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
SwitchSelector.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Selector.hpp"
5
7
8template <class Callback = EmptySelectorCallback>
9class GenericSwitchSelector : public GenericSelector<2, Callback> {
11
12 public:
16
17 void begin() override {
19 button.begin();
20 }
21
22 void update() override {
23 Parent::update();
25 if (state == AH::Button::Falling)
26 this->set(1);
27 else if (state == AH::Button::Rising)
28 this->set(0);
29 }
30
32
34 void invert() { button.invert(); }
35
36 private:
38};
39
59
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for reading and debouncing buttons and switches.
Definition Button.hpp:15
State update()
Read the button and return its new state.
Definition Button.cpp:11
State
An enumeration of the different states a button can be in.
Definition Button.hpp:45
@ Rising
Input went from low to high (0,1)
Definition Button.hpp:49
@ Falling
Input went from high to low (1,0)
Definition Button.hpp:48
void invert()
Invert the input state of this button (button pressed is HIGH instead of LOW).
Definition Button.cpp:9
State getState() const
Get the state of the button, without updating it.
Definition Button.cpp:32
void begin()
Initialize (enable the internal pull-up resistor).
Definition Button.cpp:7
void set(setting_t newSetting)
Select the given selection.
Definition Selector.hpp:93
Callback callback
Definition Selector.hpp:144
Selectable< N > & selectable
Definition Selector.hpp:141
AH::Button::State getButtonState() const
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
GenericSwitchSelector(Selectable< 2 > &selectable, const Callback &callback, const AH::Button &button)
Selector that selects one of two settings, based on the state of a toggle or momentary switch.
SwitchSelector(Selectable< 2 > &selectable, const AH::Button &button)
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32
T * begin()
Get a pointer to the first element.
Definition Array.hpp:74