HitLib 1.3.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
Groups

A LedGroup owns a set of LedStrand pointers and fans every animation command out to all of them simultaneously. Each group runs its own PROS task, multiple independent groups are fully supported with no shared state between them.


Setup

hitlib::LedStrand strand1(6, 63); // ADI port 6
hitlib::LedStrand strand2(7, 63); // ADI port 7
hitlib::LedStrand strand3(8, 63); // ADI port 8
hitlib::LedGroup groupLeft;
hitlib::LedGroup groupRight;
void initialize() {
// Build groups before calling init()
groupLeft.add(&strand1);
groupLeft.add(&strand2);
groupRight.add(&strand3);
// init() initialises hardware on every strand in the group
groupLeft.init();
groupRight.init();
// start() launches the refresh task
groupLeft.start();
groupRight.start();
}
Owns a set of LedStrand pointers and fans all animation commands out to each strand simultaneously.
Definition led_group.hpp:39
void add(LedStrand *strand)
Register a strand with this group.
void init(uint32_t refreshMs=20)
Initialize hardware on all registered strands.
void start()
Start the group refresh task.
Driver for a single WS2812B-compatible LED strip on a VEX ADI port.
Definition led_strand.hpp:53
Top-level convenience header, includes the full hitlib public API.

Fan-out behaviour

Every animation method on LedGroup calls the same method on each strand in order. All strands receive the command before any of them tick, so they stay in sync.

// Both strands in groupLeft get rainbow simultaneously
groupLeft.rainbow(1);
// groupRight gets something different
groupRight.pulse(0xFF0000, 5, 1);
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 rainbow(uint8_t speed)
Scroll a full HSV rainbow across the strip.

Targeting individual strands

Use the subscript operator to reach a specific strand when you need different animations within the same group:

groupLeft[0]->setColor(0xFF0000); // strand1 only
groupLeft[1]->setColor(0x0000FF); // strand2 only
// Fan-out still works normally for shared commands
groupLeft.setBrightness(75); // both strands
void setBrightness(uint8_t pct)
Set global brightness for this strand.
void setColor(uint32_t color)
Set all LEDs to a solid color.

refresh rate

init() accepts an optional refresh interval in milliseconds (default 20 ms = 50 Hz).

groupLeft.init(20); // 50 Hz - default, good for most animations
groupLeft.init(10); // 100 Hz - smoother twinkle / fast pulse bounce
groupLeft.init(33); // ~30 Hz - lighter CPU load

Pass 0 to fall back to each strand's own configured interval.


Multiple groups example

hitlib::LedGroup drivetrainLeds;
hitlib::LedGroup intakeLeds;
void initialize() {
drivetrainLeds.add(&strand1);
drivetrainLeds.add(&strand2);
intakeLeds.add(&strand3);
drivetrainLeds.init();
intakeLeds.init();
drivetrainLeds.start();
intakeLeds.start();
}
void opcontrol() {
drivetrainLeds.rainbow(1);
intakeLeds.twinkle({0x00FFFF, 0xFFFFFF}, 40);
}
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.