HitLib 1.3.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
led_group.hpp
Go to the documentation of this file.
1#pragma once
2#include "led_strand.hpp"
3#include "led_profile.hpp"
4#include <vector>
5
10
11namespace hitlib {
12
13// ============================================================================
14
39class LedGroup {
40public:
41
42 // ========================================================================
45
54 void add(LedStrand* strand);
55
66 void init(uint32_t refreshMs = 20);
67
73 void start();
74
76
77 // ========================================================================
82
84 void off();
85
87 void setColor(uint32_t color);
88
90 void pulse(uint32_t color, uint8_t runLength, uint8_t speed,
91 uint32_t bgColor = 0x000000, bool invert = false, bool bounce = false);
92
94 void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor = 0x000000);
95
97 void flow(uint32_t color1, uint32_t color2, uint8_t speed, bool invert = false,
98 bool seamless = true);
99
101 void rainbow(uint8_t speed);
102
104 void twinkle(const std::vector<uint32_t>& colors, uint8_t densityPct = 30,
105 uint8_t fadeStep = 16, uint32_t bgColor = 0x000000);
106
108 void bitscroll(const std::vector<LedStrand::BitScrollSegment>& segments, uint8_t speed,
109 bool invert = false, uint32_t bgColor = 0x000000, bool bounce = false,
110 uint8_t spacing = 5, bool repeating = true);
111
113 void levelFill(uint32_t color, uint32_t color2 = 0x000000, bool gradient = false,
114 uint32_t bgColor = 0x000000, bool invert = false);
115
117 void setLevel(uint8_t level);
118
120 void levelSource(LedStrand::LevelFn read, double emptyAt, double fullAt, bool wrap = false,
121 uint8_t smoothing = 0);
122
125
127 void musicSync(const LedStrand::MusicTrack& track, uint32_t color, uint32_t color2 = 0x000000,
128 bool gradient = false, uint32_t bgColor = 0x000000, bool invert = false,
129 uint8_t sensitivity = 100, bool loop = false);
130
132 void musicSeek(uint32_t positionMs);
133
135 void musicPause(bool paused = true);
136
138 void setSensitivity(uint8_t pct);
139
141 void spliceMask(uint8_t sections, bool invert = false, bool alternating = false,
142 uint32_t altPeriodMs = 100, uint32_t bgColor = 0x000000,
143 bool useOverlay = false);
144
146 void spliceMaskCustom(const std::vector<LedStrand::SpliceRegion>& regions);
147
150
152 void setBrightness(uint8_t pct);
153
155
156 // ========================================================================
159
161 void overlaySetColor(uint32_t color);
162
164 void overlayPulse(uint32_t color, uint8_t runLength, uint8_t speed,
165 uint32_t bgColor = 0x000000);
166
168 void overlayFlash(uint32_t color, uint32_t onMs, uint32_t offMs,
169 uint32_t bgColor = 0x000000);
170
172 void overlayFlow(uint32_t color1, uint32_t color2, uint8_t speed, bool seamless = true);
173
175 void overlayRainbow(uint8_t speed);
176
178
179 // ========================================================================
182
184 void attachProfile(const Profile* profile);
185
188
190 void activateMode(uint8_t modeIdx);
191
193 void activateModeTimed(uint8_t modeIdx, uint32_t durationMs);
194
196 void deactivateMode(uint8_t modeIdx);
197
199
200 // ========================================================================
203
212 LedStrand* operator[](size_t i) { return strands[i]; }
213
217 size_t size() const { return strands.size(); }
218
220
221private:
222 std::vector<LedStrand*> strands;
223 uint32_t refreshMs = 20;
224 void groupTask();
225};
226
227} // namespace hitlib
Owns a set of LedStrand pointers and fans all animation commands out to each strand simultaneously.
Definition led_group.hpp:39
void levelFill(uint32_t color, uint32_t color2=0x000000, bool gradient=false, uint32_t bgColor=0x000000, bool invert=false)
Configure the strip as a level meter, and take manual control of it.
void setBrightness(uint8_t pct)
Set global brightness for this strand.
void pulse(uint32_t color, uint8_t runLength, uint8_t speed, uint32_t bgColor=0x000000, bool invert=false, bool bounce=false)
Animate a run of color moving across a background.
void overlaySetColor(uint32_t color)
Set the overlay buffer to a solid color.
void twinkle(const std::vector< uint32_t > &colors, uint8_t densityPct=30, uint8_t fadeStep=16, uint32_t bgColor=0x000000)
Spawn randomly fading sparkles from a color palette.
void overlayFlow(uint32_t color1, uint32_t color2, uint8_t speed, bool seamless=true)
Scroll a gradient in the overlay buffer.
LedStrand * operator[](size_t i)
Access an individual strand by index.
Definition led_group.hpp:212
void overlayRainbow(uint8_t speed)
Scroll a rainbow in the overlay buffer.
void overlayPulse(uint32_t color, uint8_t runLength, uint8_t speed, uint32_t bgColor=0x000000)
Animate a moving run in the overlay buffer.
void levelSource(LedStrand::LevelFn read, double emptyAt, double fullAt, bool wrap=false, uint8_t smoothing=0)
Point the meter at a live value and let it follow it on its own.
void musicSync(const LedStrand::MusicTrack &track, uint32_t color, uint32_t color2=0x000000, bool gradient=false, uint32_t bgColor=0x000000, bool invert=false, uint8_t sensitivity=100, bool loop=false)
Fill the meter from a baked music envelope, and start playing it.
void setColor(uint32_t color)
Set all LEDs to a solid color.
void off()
Turn all LEDs off (set to black).
void rainbow(uint8_t speed)
Scroll a full HSV rainbow across the strip.
void bitscroll(const std::vector< LedStrand::BitScrollSegment > &segments, uint8_t speed, bool invert=false, uint32_t bgColor=0x000000, bool bounce=false, uint8_t spacing=5, bool repeating=true)
Scroll a pattern of colored segments across the strip.
void overlayFlash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the overlay buffer on and off (see flash()).
void spliceMask(uint8_t sections, bool invert=false, bool alternating=false, uint32_t altPeriodMs=100, uint32_t bgColor=0x000000, bool useOverlay=false)
Apply a splice mask that overrides alternating equal-width bins.
size_t size() const
Return the number of strands in this group.
Definition led_group.hpp:217
void add(LedStrand *strand)
Register a strand with this group.
void init(uint32_t refreshMs=20)
Initialize hardware on all registered strands.
void spliceMaskCustom(const std::vector< LedStrand::SpliceRegion > &regions)
Apply a splice mask made of independently placed/sized regions, each running its own animation.
void setLevel(uint8_t level)
Set how full the meter is.
void attachProfile(const Profile *profile)
Attach a Profile and reset the mode stack.
void flow(uint32_t color1, uint32_t color2, uint8_t speed, bool invert=false, bool seamless=true)
Scroll a two-color gradient across the strip.
void setSensitivity(uint8_t pct)
Change the gain applied to envelope samples without restarting.
void start()
Start the group refresh task.
void clearSpliceMask()
Remove the active splice mask, whichever kind is active.
void activateModeTimed(uint8_t modeIdx, uint32_t durationMs)
Push a timed mode onto the mode stack.
void musicPause(bool paused=true)
Pause or resume playback, holding the meter where it is.
void detachProfile()
Detach the active profile and turn the strand off.
void clearLevelSource()
Stop following a levelSource() reader, leaving the fill where it is.
void musicSeek(uint32_t positionMs)
Jump playback to a position in the song.
void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the whole strip on and off.
void deactivateMode(uint8_t modeIdx)
Remove a mode from the stack immediately.
void activateMode(uint8_t modeIdx)
Push a persistent mode onto the mode stack.
Driver for a single WS2812B-compatible LED strip on a VEX ADI port.
Definition led_strand.hpp:53
double(*)() LevelFn
Signature for the reader a fill meter follows, see levelSource().
Definition led_strand.hpp:90
Profile and mode descriptors for the hitlib event-driven animation system.
Single addressable LED strip driver with layered animation engine.
Definition led_group.hpp:11
A song's intensity envelope, baked ahead of time into one 8-bit sample per frame.
Definition led_strand.hpp:217
An immutable, statically-allocated collection of ProfileMode entries.
Definition led_profile.hpp:68