This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
ManyButtonsSelector.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Selector.hpp"
4 #include <Def/Def.hpp>
6 
8 
9 template <setting_t N, class Callback = EmptySelectorCallback>
10 class GenericManyButtonsSelector : public GenericSelector<N, Callback> {
12 
13  public:
15  const Callback &callback,
16  const PinList<N> &buttonPins)
18  buttonPins} {}
19 
20  void begin() override {
21  Parent::begin();
22  for (const pin_t &pin : buttonPins)
24  }
25 
26  void update() override {
28  for (setting_t i = 0; i < N; i++)
29  // TODO: invert?
30  if (ExtIO::digitalRead(buttonPins[i]) == LOW) {
31  if (ExtIO::digitalRead(buttonPins[this->get()]) != LOW)
32  this->set(i);
33  break;
34  }
35  }
36 
37  private:
39 };
40 
41 // -------------------------------------------------------------------------- //
42 
57 template <setting_t N>
59  public:
62  selectable,
63  {},
64  buttonPins,
65  } {}
66 };
67 
ManyButtonsSelector::ManyButtonsSelector
ManyButtonsSelector(Selectable< N > &selectable, const PinList< N > &buttonPins)
Definition: ManyButtonsSelector.hpp:60
INPUT_PULLUP
const uint8_t INPUT_PULLUP
Definition: ExtendedInputOutput.hpp:39
GenericSelector::selectable
Selectable< N > & selectable
Definition: Selector.hpp:137
SelectorBase::get
setting_t get() const
Get the current selection/setting.
Definition: Selector.hpp:47
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
GenericManyButtonsSelector
Definition: ManyButtonsSelector.hpp:10
Def.hpp
ExtendedInputOutput.hpp
Array< pin_t, N >
Selectable
Definition: Selectable.hpp:11
GenericManyButtonsSelector::GenericManyButtonsSelector
GenericManyButtonsSelector(Selectable< N > &selectable, const Callback &callback, const PinList< N > &buttonPins)
Definition: ManyButtonsSelector.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
GenericSelector::set
void set(setting_t newSetting)
Select the given selection.
Definition: Selector.hpp:89
GenericSelector
Definition: Selector.hpp:57
GenericSelector::update
void update() override
Update this updatable.
Definition: Selector.hpp:78
GenericSelector::callback
Callback callback
Definition: Selector.hpp:140
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:35
Selector.hpp
GenericManyButtonsSelector::update
void update() override
Update this updatable.
Definition: ManyButtonsSelector.hpp:26
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
ExtIO::digitalRead
int digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:56
GenericManyButtonsSelector::buttonPins
PinList< N > buttonPins
Definition: ManyButtonsSelector.hpp:38
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:63
GenericManyButtonsSelector::begin
void begin() override
Initialize this updatable.
Definition: ManyButtonsSelector.hpp:20
GenericSelector::begin
void begin() override
Initialize this updatable.
Definition: Selector.hpp:73
ManyButtonsSelector
Selector that reads from buttons.
Definition: ManyButtonsSelector.hpp:58