Control Surface master
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtonLatched.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <Def/Def.hpp>
8
10
11namespace Bankable {
12
21template <uint8_t NumBanks, class BankAddress, class Sender>
23 protected:
36 MIDIButtonLatched(BankAddress bankAddress, pin_t pin,
37 const Sender &sender)
38 : address(bankAddress), button(pin), sender(sender) {}
39
40 public:
41 void begin() override { button.begin(); }
42
43 void update() override {
45 if (state == AH::Button::Falling)
47 }
48
49 bool toggleState() {
50 bool newstate = !getState();
51 setState(newstate);
52 return newstate;
53 }
54
55 bool getState() const { return states.get(address.getSelection()); }
56
57 void setState(bool state) {
58 states.set(address.getSelection(), state);
59 if (state) {
60 sender.sendOn(address.getActiveAddress());
61 } else {
62 sender.sendOff(address.getActiveAddress());
63 }
64 }
65
67
68 protected:
69 BankAddress address;
72
73 public:
74 Sender sender;
75};
76
77} // namespace Bankable
78
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
void set(uint16_t bitIndex)
Set the value of the given bit to 1.
Definition: BitArray.hpp:43
bool get(uint16_t bitIndex) const
Get the value of the given bit.
Definition: BitArray.hpp:33
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
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 class for momentary buttons and switches that send MIDI events.
void update() override
Update this updatable.
MIDIButtonLatched(BankAddress bankAddress, pin_t pin, const Sender &sender)
Create a new bankable MIDIButtonLatched object on the given pin and address.
void begin() override
Initialize this updatable.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.