Control Surface master
MIDI Control Surface library for Arduino
LEDs.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7
8#include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
9
11
20template <uint16_t N>
21class LEDs {
22 public:
29 LEDs(const PinList<N> &ledPins) : ledPins(ledPins) {}
30
34 void begin() const {
35 for (const pin_t &pin : ledPins)
37 }
38
48 void displayRange(uint16_t startOn, uint16_t startOff) const {
49 for (uint16_t pin = 0; pin < startOn; pin++)
50 clear(pin);
51 for (uint16_t pin = startOn; pin < startOff; pin++)
52 set(pin);
53 for (uint16_t pin = startOff; pin < N; pin++)
54 clear(pin);
55 }
56
58 void set(uint16_t index) const {
59 // TODO: bounds check?
60 ExtIO::digitalWrite(ledPins[index], HIGH);
61 }
62
64 void clear(uint16_t index) const {
65 // TODO: bounds check?
66 ExtIO::digitalWrite(ledPins[index], LOW);
67 }
68
75 void displayDot(uint16_t led) const { displayRange(led, led + 1); }
76
80 void clear() const {
81 for (pin_t pin : ledPins)
83 }
84
85 private:
87};
88
90
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
A class for collections of LEDs that can display ranges.
Definition: LEDs.hpp:21
const PinList< N > ledPins
Definition: LEDs.hpp:86
void clear(uint16_t index) const
Turn off the given LED.
Definition: LEDs.hpp:64
LEDs(const PinList< N > &ledPins)
Create a LEDs object.
Definition: LEDs.hpp:29
void set(uint16_t index) const
Turn on the given LED.
Definition: LEDs.hpp:58
void begin() const
Initialize (set LED pins as outputs).
Definition: LEDs.hpp:34
void clear() const
Turn off all LEDs.
Definition: LEDs.hpp:80
void displayDot(uint16_t led) const
Turn on a single LED, and turn off all others.
Definition: LEDs.hpp:75
void displayRange(uint16_t startOn, uint16_t startOff) const
Turn on a range of the LEDs.
Definition: LEDs.hpp:48
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).