Arduino Filters master
Filter library for Arduino
DotBarDisplayLEDs.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/LEDs/LEDs.hpp>
9
11
15enum class DotBarMode : bool {
16 Bar = false,
17 Dot = true,
18};
19
28template <uint16_t N>
29class DotBarDisplayLEDs : public LEDs<N> {
30 public:
33
40 void display(uint16_t value) const {
41 if (value == 0)
42 this->clear();
43 else if (mode == DotBarMode::Bar)
44 this->displayRange(0, value);
45 else
46 this->displayDot(value - 1);
47 }
48
55 void display(float value) const { display(uint16_t(value * (N + 1))); }
56
58 DotBarMode getMode() const { return mode; }
59
66 void setMode(DotBarMode mode) { this->mode = mode; }
67
70
73
76
77 private:
79};
80
82
DotBarMode
An enumeration type to set an LED display to either bar or dot mode.
@ Dot
Turn on only the active LED.
@ Bar
Turn on a range of LEDs up to the active LED.
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
A class for LED bars.
void display(float value) const
Display the given fraction of the LED bar.
void toggleMode()
Toggle the dot/bar mode.
void setMode(DotBarMode mode)
Set the mode to either dot or bar mode.
void display(uint16_t value) const
Display the given number of LEDs on the LED bar.
DotBarMode getMode() const
Get the dot/bar mode.
DotBarDisplayLEDs(const PinList< N > &ledPins)
Constructor from list of pins.
void dotMode()
Set the mode to dot mode.
void barMode()
Set the mode to bar mode.
A class for collections of LEDs that can display ranges.
Definition: LEDs.hpp:21
const PinList< N > ledPins
Definition: LEDs.hpp:86
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