Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
LEDs.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6
8
17template <uint16_t N>
18class LEDs {
19 public:
26 LEDs(const PinList<N> &ledPins) : ledPins(ledPins) {}
27
31 void begin() const {
32 for (const pin_t &pin : ledPins)
33 ExtIO::pinMode(pin, OUTPUT);
34 }
35
46 for (uint16_t pin = 0; pin < startOn; pin++)
47 clear(pin);
48 for (uint16_t pin = startOn; pin < startOff; pin++)
49 set(pin);
50 for (uint16_t pin = startOff; pin < N; pin++)
51 clear(pin);
52 }
53
55 void set(uint16_t index) const {
56 // TODO: bounds check?
57 ExtIO::digitalWrite(ledPins[index], HIGH);
58 }
59
61 void clear(uint16_t index) const {
62 // TODO: bounds check?
63 ExtIO::digitalWrite(ledPins[index], LOW);
64 }
65
72 void displayDot(uint16_t led) const { displayRange(led, led + 1); }
73
77 void clear() const {
78 for (pin_t pin : ledPins)
79 ExtIO::digitalWrite(pin, LOW);
80 }
81
82 private:
84};
85
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
A class for collections of LEDs that can display ranges.
Definition LEDs.hpp:18
const PinList< N > ledPins
Definition LEDs.hpp:83
void clear(uint16_t index) const
Turn off the given LED.
Definition LEDs.hpp:61
LEDs(const PinList< N > &ledPins)
Create a LEDs object.
Definition LEDs.hpp:26
void set(uint16_t index) const
Turn on the given LED.
Definition LEDs.hpp:55
void begin() const
Initialize (set LED pins as outputs).
Definition LEDs.hpp:31
void clear() const
Turn off all LEDs.
Definition LEDs.hpp:77
void displayDot(uint16_t led) const
Turn on a single LED, and turn off all others.
Definition LEDs.hpp:72
void displayRange(uint16_t startOn, uint16_t startOff) const
Turn on a range of the LEDs.
Definition LEDs.hpp:45
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
Type for storing pin numbers of Extended Input/Output elements.