This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
LEDs.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
5 #include <Def/Def.hpp>
7 
9 
18 template <uint8_t N>
19 class LEDs {
20  public:
28 
32  void begin() const {
33  for (const pin_t &pin : ledPins)
34  ExtIO::pinMode(pin, OUTPUT);
35  }
36 
46  void displayRange(uint8_t startOn, uint8_t startOff) const {
47  for (uint8_t pin = 0; pin < startOn; pin++)
48  clear(pin);
49  for (uint8_t pin = startOn; pin < startOff; pin++)
50  set(pin);
51  for (uint8_t pin = startOff; pin < N; pin++)
52  clear(pin);
53  }
54 
56  void set(uint8_t index) const {
57  // TODO: bounds check?
59  }
60 
62  void clear(uint8_t index) const {
63  // TODO: bounds check?
65  }
66 
73  void displayDot(uint8_t led) const { displayRange(led, led + 1); }
74 
78  void clear() const {
79  for (pin_t pin : ledPins)
81  }
82 
83  private:
85 };
86 
ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:34
LEDs::set
void set(uint8_t index) const
Turn on the given LED.
Definition: LEDs.hpp:56
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
Def.hpp
LEDs::ledPins
const PinList< N > ledPins
Definition: LEDs.hpp:84
ExtendedInputOutput.hpp
Array< pin_t, N >
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:34
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
LEDs::begin
void begin() const
Initialize (set LED pins as outputs).
Definition: LEDs.hpp:32
LEDs::displayRange
void displayRange(uint8_t startOn, uint8_t startOff) const
Turn on a range of the LEDs.
Definition: LEDs.hpp:46
LEDs::displayDot
void displayDot(uint8_t led) const
Turn on a single LED, and turn off all others.
Definition: LEDs.hpp:73
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:35
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
LEDs
A class for collections of LEDs that can display ranges.
Definition: LEDs.hpp:19
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:38
LEDs::clear
void clear() const
Turn off all LEDs.
Definition: LEDs.hpp:78
LEDs::LEDs
LEDs(const PinList< N > &ledPins)
Create a LEDs object.
Definition: LEDs.hpp:27
LEDs::clear
void clear(uint8_t index) const
Turn off the given LED.
Definition: LEDs.hpp:62