Control Surface  1.2.0
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)
135  selectable, {ledPins}, button} {}
136 };
137 
139 
140 // -------------------------------------------------------------------------- //
141 
143 
145 
152 template <setting_t N>
154  : public GenericManyButtonsSelector<N, SelectorLEDsCallback<N>> {
155  public:
157  const PinList<N> &buttonPins,
158  const PinList<N> &ledPins)
160  selectable,
161  {ledPins},
162  buttonPins,
163  } {}
164 };
165 
167 
168 // -------------------------------------------------------------------------- //
169 
171 
173 
180 template <setting_t N>
182  : public GenericProgramChangeSelector<N, SelectorLEDsCallback<N>> {
183  public:
185  const MIDIChannelCN &address,
186  const PinList<N> &ledPins)
188  selectable,
189  {ledPins},
190  address,
191  } {}
192 };
193 
195 
196 // -------------------------------------------------------------------------- //
197 
199 
201 
209  : public GenericSwitchSelector<SelectorSingleLEDCallback> {
210  public:
212  pin_t ledPin)
214  selectable,
215  {ledPin},
216  button,
217  } {}
218 };
219 
LOW
const PinStatus_t LOW
Definition: ExtendedInputOutput.hpp:57
SwitchSelectorLED::SwitchSelectorLED
SwitchSelectorLED(Selectable< 2 > &selectable, const AH::Button &button, pin_t ledPin)
Definition: SelectorLEDs.hpp:211
GenericIncrementSelector< N, SelectorLEDsCallback< N > >::button
AH::IncrementButton button
Definition: IncrementSelector.hpp:46
SelectorSingleLEDCallback::ledPin
pin_t ledPin
Definition: SelectorLEDs.hpp:52
MIDIInputElement::address
const MIDIAddress address
Definition: MIDIInputElement.hpp:83
GenericProgramChangeSelector
Definition: ProgramChangeSelector.hpp:10
GenericEncoderSelector< N, SelectorLEDsCallback< N > >::pulsesPerStep
int8_t pulsesPerStep
Definition: EncoderSelector.hpp:60
GenericIncrementDecrementSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: IncrementDecrementSelector.hpp:50
GenericSwitchSelector
Definition: SwitchSelector.hpp:9
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:39
ProgramChangeSelectorLEDs::ProgramChangeSelectorLEDs
ProgramChangeSelectorLEDs(Selectable< N > &selectable, const MIDIChannelCN &address, const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:184
ManyButtonsSelectorLEDs
Selector that reads from buttons. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:154
IncrementDecrementSelector.hpp
Def.hpp
AH::IncrementDecrementButtons
A class for buttons that increment and decrement some counter or setting.
Definition: IncrementDecrementButtons.hpp:25
IncrementSelectorLEDs::IncrementSelectorLEDs
IncrementSelectorLEDs(Selectable< N > &selectable, const AH::Button &button, const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:132
GenericEncoderSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: EncoderSelector.hpp:61
MIDIChannelCN
A class for saving a MIDI channel and cable number.
Definition: MIDIAddress.hpp:19
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:100
AH::ExtIO::digitalWrite
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:48
EncoderSelector.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
HIGH
const PinStatus_t HIGH
Definition: ExtendedInputOutput.hpp:56
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:156
OUTPUT
const PinMode_t OUTPUT
Definition: ExtendedInputOutput.hpp:60
IncrementSelector.hpp
SelectorLEDsCallback::update
void update()
Refresh, called periodically.
Definition: SelectorLEDs.hpp:23
GenericIncrementSelector
Definition: IncrementSelector.hpp:9
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:209
SelectorSingleLEDCallback
Definition: SelectorLEDs.hpp:35
SelectorLEDsCallback::SelectorLEDsCallback
SelectorLEDsCallback(const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:12
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
AH::ExtIO::pinMode
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:36
GenericEncoderSelector
Definition: EncoderSelector.hpp:16
EncoderSelectorLEDs
Selector that reads from a rotary encoder. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:72
GenericSelector< N, SelectorLEDsCallback< N > >::selectable
Selectable< N > & selectable
Definition: Selector.hpp:142
GenericIncrementDecrementSelector< N, SelectorLEDsCallback< N > >::buttons
AH::IncrementDecrementButtons buttons
Definition: IncrementDecrementSelector.hpp:49
ProgramChangeSelectorLEDs
Selector that listens for MIDI Program Change events on a given MIDI Channel, and uses the program nu...
Definition: SelectorLEDs.hpp:182
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:130
EncoderSwitchPinList
A struct for the pins of a rotary (quadrature) encoder with a switch.
Definition: Def.hpp:30