This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
SelectorLEDs.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Def/Def.hpp>
5 #include <Selectors/Selector.hpp>
6 
8 
9 template <setting_t N>
11  public:
13 
15  void begin() {
16  for (pin_t pin : ledPins) {
17  ExtIO::pinMode(pin, OUTPUT);
19  }
20  }
21 
23  void update() {}
24 
26  void update(setting_t oldSetting, setting_t newSetting) {
27  ExtIO::digitalWrite(ledPins[oldSetting], LOW);
28  ExtIO::digitalWrite(ledPins[newSetting], HIGH);
29  }
30 
31  private:
33 };
34 
36  public:
38 
41 
43  void update() {}
44 
46  void update(setting_t oldSetting, setting_t newSetting) {
47  (void)oldSetting;
48  ExtIO::digitalWrite(ledPin, newSetting == 0 ? LOW : HIGH);
49  }
50 
51  private:
53 };
54 
56 
57 // -------------------------------------------------------------------------- //
58 
59 
60 #if defined(Encoder_h_) || defined(IDE)
62 
64 
71 template <setting_t N>
73  : public GenericEncoderSelector<N, SelectorLEDsCallback<N>> {
74  public:
76  const EncoderSwitchPinList &pins,
77  const PinList<N> &ledPins, int8_t pulsesPerStep = 4,
80  selectable, {ledPins}, pins, pulsesPerStep, wrap,
81  } {}
82 };
83 
85 #endif
86 
87 // -------------------------------------------------------------------------- //
88 
90 
92 
99 template <setting_t N>
101  : public GenericIncrementDecrementSelector<N, SelectorLEDsCallback<N>> {
102  public:
105  const PinList<N> &ledPins,
106  Wrap wrap = Wrap::Wrap)
108  selectable,
109  {ledPins},
110  buttons,
111  wrap,
112  } {}
113 };
114 
116 
117 // -------------------------------------------------------------------------- //
118 
120 
122 
129 template <setting_t N>
131  : public GenericIncrementSelector<N, SelectorLEDsCallback<N>> {
132  public:
134  const PinList<N> &ledPins, Wrap wrap = Wrap::Wrap)
136  selectable,
137  {ledPins},
138  button,
139  wrap,
140  } {}
141 };
142 
144 
145 // -------------------------------------------------------------------------- //
146 
148 
150 
157 template <setting_t N>
159  : public GenericManyButtonsSelector<N, SelectorLEDsCallback<N>> {
160  public:
162  const PinList<N> &buttonPins,
163  const PinList<N> &ledPins)
165  selectable,
166  {ledPins},
167  buttonPins,
168  } {}
169 };
170 
172 
173 // -------------------------------------------------------------------------- //
174 
176 
178 
185 template <setting_t N>
187  : public GenericProgramChangeSelector<N, SelectorLEDsCallback<N>> {
188  public:
190  const MIDICNChannel &address,
191  const PinList<N> &ledPins)
193  selectable,
194  {ledPins},
195  address,
196  } {}
197 };
198 
200 
201 // -------------------------------------------------------------------------- //
202 
204 
206 
214  : public GenericSwitchSelector<SelectorSingleLEDCallback> {
215  public:
217  pin_t ledPin)
219  selectable,
220  {ledPin},
221  button,
222  } {}
223 };
224 
SelectorSingleLEDCallback::ledPin
pin_t ledPin
Definition: SelectorLEDs.hpp:52
GenericEncoderSelector< N, SelectorLEDsCallback< N > >::pulsesPerStep
int8_t pulsesPerStep
Definition: EncoderSelector.hpp:60
GenericSelector< N, SelectorLEDsCallback< N > >::selectable
Selectable< N > & selectable
Definition: Selector.hpp:137
GenericProgramChangeSelector
Definition: ProgramChangeSelector.hpp:9
SelectorSingleLEDCallback::update
void update()
Refresh, called periodically.
Definition: SelectorLEDs.hpp:43
SelectorSingleLEDCallback::begin
void begin()
Initialize.
Definition: SelectorLEDs.hpp:40
GenericSwitchSelector
Definition: SwitchSelector.hpp:9
ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:34
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:15
GenericSwitchSelector< SelectorSingleLEDCallback >::button
Button button
Definition: SwitchSelector.hpp:38
GenericIncrementDecrementSelector< N, SelectorLEDsCallback< N > >::buttons
IncrementDecrementButtons buttons
Definition: IncrementDecrementSelector.hpp:46
GenericManyButtonsSelector
Definition: ManyButtonsSelector.hpp:10
ManyButtonsSelectorLEDs
Selector that reads from buttons. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:158
IncrementDecrementSelector.hpp
Def.hpp
EncoderSelectorLEDs::EncoderSelectorLEDs
EncoderSelectorLEDs(Selectable< N > &selectable, const EncoderSwitchPinList &pins, const PinList< N > &ledPins, int8_t pulsesPerStep=4, Wrap wrap=Wrap::Wrap)
Definition: SelectorLEDs.hpp:75
ExtendedInputOutput.hpp
SelectorSingleLEDCallback::SelectorSingleLEDCallback
SelectorSingleLEDCallback(pin_t ledPin)
Definition: SelectorLEDs.hpp:37
Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:20
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
SelectorLEDsCallback::update
void update()
Refresh, called periodically.
Definition: SelectorLEDs.hpp:23
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:34
SelectorLEDsCallback::update
void update(setting_t oldSetting, setting_t newSetting)
Called when the setting changes.
Definition: SelectorLEDs.hpp:26
EncoderSelector.hpp
GenericIncrementSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: IncrementSelector.hpp:38
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
ExtIO::digitalWrite
void digitalWrite(pin_t pin, uint8_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:45
Wrap
Wrap
An enumeration to set the behavior of selectors that are incremented (decremented) beyond their maxim...
Definition: Selector.hpp:14
GenericIncrementDecrementSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: IncrementDecrementSelector.hpp:47
SelectorSingleLEDCallback::update
void update(setting_t oldSetting, setting_t newSetting)
Called when the setting changes.
Definition: SelectorLEDs.hpp:46
SelectorLEDsCallback
Definition: SelectorLEDs.hpp:10
GenericEncoderSelector< N, SelectorLEDsCallback< N > >::wrap
Wrap wrap
Definition: EncoderSelector.hpp:61
IncrementSelector.hpp
SelectorLEDsCallback::begin
void begin()
Initialize.
Definition: SelectorLEDs.hpp:15
IncrementDecrementSelectorLEDs::IncrementDecrementSelectorLEDs
IncrementDecrementSelectorLEDs(Selectable< N > &selectable, const IncrementDecrementButtons &buttons, const PinList< N > &ledPins, Wrap wrap=Wrap::Wrap)
Definition: SelectorLEDs.hpp:103
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:35
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:213
SelectorSingleLEDCallback
Definition: SelectorLEDs.hpp:35
SelectorLEDsCallback::ledPins
PinList< N > ledPins
Definition: SelectorLEDs.hpp:32
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
SelectorLEDsCallback::SelectorLEDsCallback
SelectorLEDsCallback(const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:12
SwitchSelector.hpp
GenericManyButtonsSelector< N, SelectorLEDsCallback< N > >::buttonPins
PinList< N > buttonPins
Definition: ManyButtonsSelector.hpp:38
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:63
Wrap::Wrap
When the maximum (minimum) setting is reached, wrap around to the minimum (maximum) setting.
IncrementDecrementButtons
A class for buttons that increment and decrement some counter or setting.
Definition: IncrementDecrementButtons.hpp:22
GenericEncoderSelector
Definition: EncoderSelector.hpp:16
EncoderSelectorLEDs
Selector that reads from a rotary encoder. This version displays the setting using LEDs.
Definition: SelectorLEDs.hpp:72
ManyButtonsSelectorLEDs::ManyButtonsSelectorLEDs
ManyButtonsSelectorLEDs(Selectable< N > &selectable, const PinList< N > &buttonPins, const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:161
ProgramChangeSelectorLEDs::ProgramChangeSelectorLEDs
ProgramChangeSelectorLEDs(Selectable< N > &selectable, const MIDICNChannel &address, const PinList< N > &ledPins)
Definition: SelectorLEDs.hpp:189
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:38
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
ProgramChangeSelectorLEDs
Selector that listens for MIDI Program Change events on a given MIDI Channel, and uses the program nu...
Definition: SelectorLEDs.hpp:186
SwitchSelectorLED::SwitchSelectorLED
SwitchSelectorLED(Selectable< 2 > &selectable, const Button &button, pin_t ledPin)
Definition: SelectorLEDs.hpp:216
IncrementSelectorLEDs::IncrementSelectorLEDs
IncrementSelectorLEDs(Selectable< N > &selectable, const Button &button, const PinList< N > &ledPins, Wrap wrap=Wrap::Wrap)
Definition: SelectorLEDs.hpp:133
ProgramChangeSelector.hpp
GenericIncrementDecrementSelector
Definition: IncrementDecrementSelector.hpp:9
GenericIncrementSelector< N, SelectorLEDsCallback< N > >::button
IncrementButton button
Definition: IncrementSelector.hpp:37
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:43