HitLib 1.3.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
hitlib::Sequencer Class Reference

Forward declaration. More...

#include <led_sequencer.hpp>

Classes

struct  Phase
 One phase in the animation sequence. More...

Public Member Functions

constexpr Sequencer (const Phase *phases, uint8_t count)
 Construct a Sequencer from a static phase array.
void start (LedStrand &strand)
 Start the sequence from phase 0.
void stop ()
 Stop the sequence without advancing.
void update (LedStrand &strand)
 Advance the sequence, call every tick from an onTick callback.
bool isRunning () const
 Returns true if the sequence is currently running.

Detailed Description

Forward declaration.

Drives a looping sequence of timed animation phases on a LedStrand.

A Sequencer holds a pointer to a statically-allocated array of Phase descriptors. It carries its own runtime state (current phase, timestamp, running flag) so that multiple Sequencer instances can run independently on different strands without interfering with each other.

Typical usage inside a Profile

static void phase1(hitlib::LedStrand& s) { s.flash(0xFFFF00, 150, 150); }
static void phase2(hitlib::LedStrand& s) { s.rainbow(2); }
static const hitlib::Sequencer::Phase egPhases[] = {
{2000, phase1},
{8000, phase2},
};
static hitlib::Sequencer endgameSeq(egPhases, 2);
static void egActivate(hitlib::LedStrand& s) { endgameSeq.start(s); }
static void egTick (hitlib::LedStrand& s) { endgameSeq.update(s); }
static const hitlib::ProfileMode modes[] = {
{"Endgame", 100, egActivate, egTick},
};
Driver for a single WS2812B-compatible LED strip on a VEX ADI port.
Definition led_strand.hpp:53
void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the whole strip on and off.
void rainbow(uint8_t speed)
Scroll a full HSV rainbow across the strip.
One phase in the animation sequence.
Definition led_sequencer.hpp:53
Note
Sequencer is not thread-safe by itself. It is driven from LedStrand::tick() which already holds the strand mutex when calling onTick, so no additional locking is required in normal use.

Constructor & Destructor Documentation

◆ Sequencer()

hitlib::Sequencer::Sequencer ( const Phase * phases,
uint8_t count )
inlineconstexpr

Construct a Sequencer from a static phase array.

Parameters
phasesPointer to a statically-allocated Phase array. Must remain valid for the lifetime of the Sequencer.
countNumber of elements in phases.

Member Function Documentation

◆ start()

void hitlib::Sequencer::start ( LedStrand & strand)

Start the sequence from phase 0.

Calls phases[0].startFn(strand) immediately. Typically called from a ProfileMode onActivate callback.

Parameters
strandThe strand to animate.

◆ stop()

void hitlib::Sequencer::stop ( )

Stop the sequence without advancing.

The strand animation is not changed, it simply stops being updated.

◆ update()

void hitlib::Sequencer::update ( LedStrand & strand)

Advance the sequence, call every tick from an onTick callback.

Checks whether the current phase has expired. If so, advances to the next phase (wrapping to 0) and calls its startFn. Does nothing if the sequencer is not running.

Parameters
strandThe strand to animate.

◆ isRunning()

bool hitlib::Sequencer::isRunning ( ) const
inline

Returns true if the sequence is currently running.