Control Surface new-input
MIDI Control Surface library for Arduino
Abstract/MIDIButton.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AH/Hardware/Button.hpp>
4 #include <Def/Def.hpp>
6 
8 
16 template <class Sender>
17 class MIDIButton : public MIDIOutputElement {
18  public:
30  MIDIButton(pin_t pin, MIDIAddress address, const Sender &sender)
31  : button(pin), address(address), sender(sender) {}
32 
33  void begin() override { button.begin(); }
34  void update() override {
36  if (state == AH::Button::Falling) {
37  sender.sendOn(address);
38  } else if (state == AH::Button::Rising) {
39  sender.sendOff(address);
40  }
41  }
42 
43 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
44  void invert() { button.invert(); }
45 #endif
46 
48 
49  private:
52 
53  public:
54  Sender sender;
55 };
56 
#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:17
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
@ Rising
Input went from low to high (0,1)
Definition: Button.hpp:57
@ Falling
Input went from high to low (1,0)
Definition: Button.hpp:56
AH_INDIVIDUAL_BUTTON_INVERT_STATIC void invert()
Invert the state of all buttons, or of this specific 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,...
An abstract class for momentary push buttons that send MIDI events.
const MIDIAddress address
AH::Button::State getButtonState() const
MIDIButton(pin_t pin, MIDIAddress address, const Sender &sender)
Construct a new MIDIButton.
void update() override
Update this updatable.
void begin() override
Initialize this updatable.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).