Control Surface  1.1.1
MIDI Control Surface library for Arduino
SelectorLEDs.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Def/Def.hpp>
5 #include <Selectors/Selector.hpp>
6 
8 
9 template <setting_t N>
11  public:
12  SelectorLEDsCallback(const PinList<N> &ledPins) : ledPins{ledPins} {}
13 
15  void begin() {
16  for (pin_t pin : ledPins) {
19  }
20  }
21 
23  void update() {}
24 
26  void update(setting_t oldSetting, setting_t newSetting) {
27  AH::ExtIO::digitalWrite(ledPins[oldSetting], LOW);
28  AH::ExtIO::digitalWrite(ledPins[newSetting], HIGH);
29  }
30 
31  private:
32  PinList<N> ledPins;
33 };
34 
36  public:
38 
41 
43  void update() {}
44 
46  void update(setting_t oldSetting, setting_t newSetting) {
47  (void)oldSetting;
48  AH::ExtIO::digitalWrite(ledPin, newSetting == 0 ? LOW : HIGH);
49  }
50 
51  private:
53 };
54 
56 
57 // -------------------------------------------------------------------------- //
58 
59 #if defined(Encoder_h_) || defined(IDE)
61 
63 
70 template <setting_t N>
72  : public GenericEncoderSelector<N, SelectorLEDsCallback<N>> {
73  public:
75  const EncoderSwitchPinList &pins,
76  const PinList<N> &ledPins, int8_t pulsesPerStep = 4,
79  selectable, {ledPins}, pins, pulsesPerStep, wrap,
80  } {}
81 };
82 
84 #endif
85 
86 // -------------------------------------------------------------------------- //
87 
89 
91 
98 template <setting_t N>
100  : public GenericIncrementDecrementSelector<N, SelectorLEDsCallback<N>> {
101  public:
104  const PinList<N> &ledPins,
105  Wrap wrap = Wrap::Wrap)
107  selectable,
108  {ledPins},
109  buttons,
110  wrap,
111  } {}
112 };
113 
115 
116 // -------------------------------------------------------------------------- //
117 
119 
121 
128 template <setting_t N>
130  : public GenericIncrementSelector<N, SelectorLEDsCallback<N>> {
131  public:
133  const PinList<N> &ledPins, Wrap wrap = Wrap::Wrap)
135  selectable,
136  {ledPins},
137  button,
138  wrap,
139  } {}
140 };
141 
143 
144 // -------------------------------------------------------------------------- //
145 
147 
149 
156 template <setting_t N>
158  : public GenericManyButtonsSelector<N, SelectorLEDsCallback<N>> {
159  public:
161  const PinList<N> &buttonPins,
162  const PinList<N> &ledPins)
164  selectable,
165  {ledPins},
166  buttonPins,
167  } {}
168 };
169 
171 
172 // -------------------------------------------------------------------------- //
173 
175 
177 
184 template <setting_t N>
186  : public GenericProgramChangeSelector<N, SelectorLEDsCallback<N>> {
187  public:
189  const MIDICNChannel &address,
190  const PinList<N> &ledPins)
192  selectable,
193  {ledPins},
194  address,
195  } {}
196 };
197 
199 
200 // -------------------------------------------------------------------------- //
201 
203 
205 
213  : public GenericSwitchSelector<SelectorSingleLEDCallback> {
214  public:
216  pin_t ledPin)
218  selectable,
219  {ledPin},
220  button,
221  } {}
222 };
223 
AH::ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:36
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
SwitchSelectorLED::SwitchSelectorLED
SwitchSelectorLED(Selectable< 2 > &selectable, const AH::Button &button, pin_t ledPin)
Definition: SelectorLEDs.hpp:215
GenericIncrementSelector< N, SelectorLEDsCallback< N > >::button
AH::IncrementButton button
Definition: IncrementSelector.hpp:39
SelectorSingleLEDCallback::ledPin
pin_t ledPin
Definition: SelectorLEDs.hpp:52
GenericProgramChangeSelector
Definition: ProgramChangeSelector.hpp:9
GenericEncoderSelector< N, SelectorLEDsCallback< N > >::pulsesPerStep
int8_t pulsesPerStep
Definition: EncoderSelector.hpp:60
GenericIncrementDecrementSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: IncrementDecrementSelector.hpp:46
GenericSwitchSelector
Definition: SwitchSelector.hpp:9
ProgramChangeSelectorLEDs::ProgramChangeSelectorLEDs
ProgramChangeSelectorLEDs(Selectable< N > &selectable, const MIDICNChannel &address, const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:188
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
SelectorLEDsCallback::update
void update(setting_t oldSetting, setting_t newSetting)
Called when the setting changes.
Definition: SelectorLEDs.hpp:26
SelectorSingleLEDCallback::update
void update()
Refresh, called periodically.
Definition: SelectorLEDs.hpp:43
GenericManyButtonsSelector
Definition: ManyButtonsSelector.hpp:10
EncoderSelectorLEDs::EncoderSelectorLEDs
EncoderSelectorLEDs(Selectable< N > &selectable, const EncoderSwitchPinList &pins, const PinList< N > &ledPins, int8_t pulsesPerStep=4, Wrap wrap=Wrap::Wrap)
Definition: SelectorLEDs.hpp:74
GenericManyButtonsSelector< N, SelectorLEDsCallback< N > >::buttonPins
PinList< N > buttonPins
Definition: ManyButtonsSelector.hpp:38
ManyButtonsSelectorLEDs
Selector that reads from buttons. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:157
IncrementDecrementSelector.hpp
Def.hpp
AH::IncrementDecrementButtons
A class for buttons that increment and decrement some counter or setting.
Definition: IncrementDecrementButtons.hpp:25
GenericEncoderSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: EncoderSelector.hpp:61
ExtendedInputOutput.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Selectable
Definition: Selectable.hpp:11
IncrementDecrementSelectorLEDs
Selector with two buttons (one to increment, one to decrement). This version displays the setting usi...
Definition: SelectorLEDs.hpp:99
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:46
EncoderSelector.hpp
IncrementSelectorLEDs::IncrementSelectorLEDs
IncrementSelectorLEDs(Selectable< N > &selectable, const AH::Button &button, const PinList< N > &ledPins, Wrap wrap=Wrap::Wrap)
Definition: SelectorLEDs.hpp:132
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
SelectorSingleLEDCallback::SelectorSingleLEDCallback
SelectorSingleLEDCallback(pin_t ledPin)
Definition: SelectorLEDs.hpp:37
SelectorSingleLEDCallback::begin
void begin()
Initialize.
Definition: SelectorLEDs.hpp:40
Wrap
Wrap
An enumeration to set the behavior of selectors that are incremented (decremented) beyond their maxim...
Definition: Selector.hpp:14
SelectorLEDsCallback
Definition: SelectorLEDs.hpp:10
IncrementDecrementSelectorLEDs::IncrementDecrementSelectorLEDs
IncrementDecrementSelectorLEDs(Selectable< N > &selectable, const AH::IncrementDecrementButtons &buttons, const PinList< N > &ledPins, Wrap wrap=Wrap::Wrap)
Definition: SelectorLEDs.hpp:102
ManyButtonsSelectorLEDs::ManyButtonsSelectorLEDs
ManyButtonsSelectorLEDs(Selectable< N > &selectable, const PinList< N > &buttonPins, const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:160
IncrementSelector.hpp
SelectorLEDsCallback::update
void update()
Refresh, called periodically.
Definition: SelectorLEDs.hpp:23
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:47
GenericIncrementSelector
Definition: IncrementSelector.hpp:9
MIDICNChannel
A class for saving a MIDI channel and cable number.
Definition: MIDICNChannelAddress.hpp:19
ManyButtonsSelector.hpp
Selector.hpp
SwitchSelectorLED
Selector that selects one of two settings, based on the state of a toggle or momentary switch....
Definition: SelectorLEDs.hpp:212
SelectorSingleLEDCallback
Definition: SelectorLEDs.hpp:35
SelectorLEDsCallback::SelectorLEDsCallback
SelectorLEDsCallback(const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:12
GenericIncrementSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: IncrementSelector.hpp:40
SelectorLEDsCallback::begin
void begin()
Initialize.
Definition: SelectorLEDs.hpp:15
SwitchSelector.hpp
GenericSwitchSelector< SelectorSingleLEDCallback >::button
AH::Button button
Definition: SwitchSelector.hpp:38
SelectorSingleLEDCallback::update
void update(setting_t oldSetting, setting_t newSetting)
Called when the setting changes.
Definition: SelectorLEDs.hpp:46
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:50
Wrap::Wrap
When the maximum (minimum) setting is reached, wrap around to the minimum (maximum) setting.
GenericEncoderSelector
Definition: EncoderSelector.hpp:16
EncoderSelectorLEDs
Selector that reads from a rotary encoder. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:71
GenericSelector< N, SelectorLEDsCallback< N > >::selectable
Selectable< N > & selectable
Definition: Selector.hpp:137
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:50
AH::ExtIO::digitalWrite
void digitalWrite(pin_t pin, uint8_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:48
GenericIncrementDecrementSelector< N, SelectorLEDsCallback< N > >::buttons
AH::IncrementDecrementButtons buttons
Definition: IncrementDecrementSelector.hpp:45
ProgramChangeSelectorLEDs
Selector that listens for MIDI Program Change events on a given MIDI Channel, and uses the program nu...
Definition: SelectorLEDs.hpp:185
ProgramChangeSelector.hpp
GenericIncrementDecrementSelector
Definition: IncrementDecrementSelector.hpp:9
SelectorLEDsCallback::ledPins
PinList< N > ledPins
Definition: SelectorLEDs.hpp:32
IncrementSelectorLEDs
Selector with one button that increments the selection. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:129
EncoderSwitchPinList
A struct for the pins of a rotary (quadrature) encoder with a switch.
Definition: Def.hpp:30