Arduino Helpers master
Utility library for Arduino
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:
27
31 void begin() const {
32 for (const pin_t &pin : ledPins)
34 }
35
45 void displayRange(uint16_t startOn, uint16_t startOff) const {
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?
58 }
59
61 void clear(uint16_t index) const {
62 // TODO: bounds check?
64 }
65
72 void displayDot(uint16_t led) const { displayRange(led, led + 1); }
73
77 void clear() const {
78 for (pin_t pin : ledPins)
80 }
81
82 private:
84};
85
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
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
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.