Control Surface master
MIDI Control Surface library for Arduino
Abstract/MIDIButtonLatched.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6#include <Def/Def.hpp>
8
10
19template <class Sender>
21 protected:
35 : button(pin), address(address), sender(sender) {}
36
37 public:
38 void begin() final override { button.begin(); }
39 void update() final override {
43 }
44
47 bool toggleState() {
49 return getState();
50 }
51
53 bool getState() const { return state; }
54
57 void setState(bool state) {
58 this->state = state;
59 state ? sender.sendOn(address) : sender.sendOff(address);
60 }
61
63 void invert() { button.invert(); }
64
67
69 MIDIAddress getAddress() const { return this->address; }
72 void setAddressUnsafe(MIDIAddress address) { this->address = address; }
73
74 private:
77 bool state = false;
78
79 public:
80 Sender sender;
81};
82
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
State update()
Read the button and return its new state.
Definition: Button.cpp:13
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:48
@ Falling
Input went from high to low (1,0)
Definition: Button.hpp:51
void invert()
Invert the input state of this button (button pressed is HIGH instead of LOW).
Definition: Button.cpp:11
State getState() const
Get the state of the button, without updating it.
Definition: Button.cpp:34
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:9
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:173
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
A class for momentary buttons and switches that send MIDI events.
MIDIButtonLatched(pin_t pin, MIDIAddress address, const Sender &sender)
Create a new MIDIButtonLatched object on the given pin and address.
bool getState() const
Get the current state.
void setAddressUnsafe(MIDIAddress address)
Set the MIDI address.
AH::Button::State getButtonState() const
Get the state of the underlying button.
bool toggleState()
Flip the state (on → off or off → on).
MIDIAddress getAddress() const
Get the MIDI address.
void begin() final override
Initialize this updatable.
void setState(bool state)
Set the state to the given value.
void update() final override
Update this updatable.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).