Control Surface main
MIDI Control Surface library for Arduino
Bankable/Abstract/MIDIButtonLatching.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <Def/Def.hpp>
7
9
10namespace Bankable {
11
19template <class BankAddress, class Sender>
21 protected:
33 MIDIButtonLatching(BankAddress bankAddress, pin_t pin,
34 const Sender &sender)
35 : address(bankAddress), button(pin), sender(sender) {}
36
37 public:
38 void begin() override { button.begin(); }
39 void update() override {
41 if (state == AH::Button::Falling || state == AH::Button::Rising) {
42 MIDIAddress sendAddress = address.getActiveAddress();
43 sender.sendOn(sendAddress);
44 sender.sendOff(sendAddress);
45 }
46 }
47
49
50 protected:
51 BankAddress address;
53
54 public:
55 Sender sender;
56};
57
58} // namespace Bankable
59
#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
@ Rising
Input went from low to high (0,1)
Definition: Button.hpp:52
@ 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 latching buttons and switches that send MIDI events.
MIDIButtonLatching(BankAddress bankAddress, pin_t pin, const Sender &sender)
Construct a new MIDIButtonLatching.
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
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.