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

Driver for a single WS2812B-compatible LED strip on a VEX ADI port. More...

#include <led_strand.hpp>

Classes

struct  BitScrollSegment
 One colored segment in a bitscroll pattern. More...
struct  GaugeStop
 One color on a GAUGE region's scale. More...
struct  SpliceRegion
 One independently placed override region for a custom splice mask. More...
struct  MusicTrack
 A song's intensity envelope, baked ahead of time into one 8-bit sample per frame. More...

Public Types

Types
enum class  SpliceRegionAnimKind : uint8_t {
  OFF ,
  SOLID ,
  PULSE ,
  FLASH ,
  FLOW ,
  RAINBOW ,
  TWINKLE ,
  BITSCROLL ,
  GAUGE
}
 What a custom splice mask region shows. More...
enum class  GaugeStyle : uint8_t {
  HEAT ,
  BAR
}
 How a GAUGE region turns its level into pixels. More...
enum class  GaugeBlend : uint8_t {
  LERP ,
  STEP
}
 How a GAUGE region moves between two stops. More...
using LevelFn
 Signature for the reader a fill meter follows, see levelSource().

Public Member Functions

Construction
 LedStrand (uint8_t adiPort, uint8_t length, uint32_t refreshMs=20)
 Construct a strand on a standard ADI port.
 LedStrand (uint8_t smartPort, uint8_t adiPort, uint8_t length, uint32_t refreshMs=20)
 Construct a strand on an ADI expander port.
Initialization
void init ()
 Initialize the hardware LED object.
void tick ()
 Advance one animation frame.
Base Animations

All methods are thread-safe.

Changes take effect on the next refresh tick.

void off ()
 Turn all LEDs off (set to black).
void setColor (uint32_t color)
 Set all LEDs to a solid color.
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 flash (uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
 Blink the whole strip on and off.
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 rainbow (uint8_t speed)
 Scroll a full HSV rainbow across the strip.
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 bitscroll (const std::vector< 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.
Level Meter & Music Sync

A meter fills the strip from one end in proportion to a 0-255 level.

levelFill() decides what it looks like, and one of three things decides how full it is:

  • setLevel(), called from your own code;
  • levelSource(), which polls a value for you every tick, so a battery gauge or a motor-heat bar needs no code in your control loop at all;
  • musicSync(), which plays a baked MusicTrack so the strip fills and empties in time with a song.

The three are mutually exclusive: whichever was set up last is what drives the meter, so handing it to a song doesn't leave a stale sensor fighting it for the same pixels.

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 setLevel (uint8_t level)
 Set how full the meter is.
uint8_t getLevel () const
 Return the meter's current level (0-255).
void levelSource (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 clearLevelSource ()
 Stop following a levelSource() reader, leaving the fill where it is.
bool levelSourceActive () const
 Whether a levelSource() reader is currently driving the meter.
void musicSync (const 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 musicSeek (uint32_t positionMs)
 Jump playback to a position in the song.
void musicPause (bool paused=true)
 Pause or resume playback, holding the meter where it is.
bool musicPlaying () const
 Whether a MusicTrack is attached and not paused.
uint32_t musicPositionMs () const
 Current playback position in milliseconds.
void setSensitivity (uint8_t pct)
 Change the gain applied to envelope samples without restarting.
Overlay Animations

Write into a second buffer, shown in spliceMask()'s masked bins instead of bgColor when useOverlay is set.

void overlaySetColor (uint32_t color)
 Set the overlay buffer to a solid color.
void overlayPulse (uint32_t color, uint8_t runLength, uint8_t speed, uint32_t bgColor=0x000000)
 Animate a moving run in the overlay buffer.
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 overlayFlow (uint32_t color1, uint32_t color2, uint8_t speed, bool seamless=true)
 Scroll a gradient in the overlay buffer.
void overlayRainbow (uint8_t speed)
 Scroll a rainbow in the overlay buffer.
void overlayTwinkle (const std::vector< uint32_t > &colors, uint8_t densityPct=30, uint8_t fadeStep=16, uint32_t bgColor=0x000000)
 Sparkle random pixels of the overlay buffer (see twinkle()).
void overlayBitscroll (const std::vector< BitScrollSegment > &segments, uint8_t speed, bool invert=false, uint32_t bgColor=0x000000, uint8_t spacing=5, bool repeating=true)
 Scroll a repeating bit pattern in the overlay buffer (see bitscroll()).
Brightness
void setBrightness (uint8_t pct)
 Set global brightness for this strand.
uint8_t getBrightness () const
 Return the current brightness percentage.
Profile System
void attachProfile (const Profile *profile)
 Attach a Profile and reset the mode stack.
void detachProfile ()
 Detach the active profile and turn the strand off.
void activateMode (uint8_t modeIdx)
 Push a persistent mode onto the mode stack.
void activateModeTimed (uint8_t modeIdx, uint32_t durationMs)
 Push a timed mode onto the mode stack.
void deactivateMode (uint8_t modeIdx)
 Remove a mode from the stack immediately.
Accessors
uint8_t getLength () const
 Return the number of LEDs in this strand.

Static Public Attributes

static constexpr uint8_t MAX_LEDS

Splice Mask

Overrides part of the strip, either as equal alternating bins sharing one overlay buffer (spliceMask) or as arbitrarily placed regions that each animate independently (spliceMaskCustom).

The two are mutually exclusive, whichever was called most recently is what's active.

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.
void spliceMaskCustom (const std::vector< SpliceRegion > &regions)
 Apply a splice mask made of independently placed/sized regions, each running its own animation.
void setRegionLevel (uint8_t regionIdx, uint8_t level)
 Set how full a hand-driven GAUGE region is.
void clearSpliceMask ()
 Remove the active splice mask, whichever kind is active.
static SpliceRegion motorHeatGauge (uint8_t start, uint8_t width, LevelFn read=nullptr)
 A GAUGE region pre-loaded with the V5 motor's own heat schedule.

Detailed Description

Driver for a single WS2812B-compatible LED strip on a VEX ADI port.

LedStrand owns one hardware pros::adi::Led and drives it from a task-managed refresh loop via LedGroup. All public animation methods are thread-safe, they take effect on the next refresh tick.

Layer model

base buffer <- flow / rainbow / pulse / bitscroll / twinkle, or a
level meter driven by hand, by a live value, or by a
music envelope
overlay buffer <- second independent animation
spliceMask <- final per-pixel override (bgColor or overlay), by
equal alternating bins or by arbitrary regions
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.
void rainbow(uint8_t speed)
Scroll a full HSV rainbow across the strip.
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 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 bitscroll(const std::vector< 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 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.

Typical setup

hitlib::LedStrand strand(6, 63); // ADI port 6, 63 LEDs
void initialize() {
group.add(&strand);
group.init();
group.start();
}
void opcontrol() {
strand.rainbow(1);
}
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
See also
LedGroup

Member Typedef Documentation

◆ LevelFn

Signature for the reader a fill meter follows, see levelSource().

Called once per refresh tick, from the LedGroup task rather than from your loop, and expected to just read something and return it, in whatever units that something already speaks.

A capture-less lambda converts to one of these, which is how it usually gets written:

pros::Motor intake(11);
strand.levelSource([] { return intake.get_temperature(); }, 20.0, 70.0);

A lambda has to actually return a double, so a reading that comes back as an integer needs saying so: [] { return (double)rot.get_angle(); }.

Note
Because the reader runs on the LED task, it must not block, and must not take a lock your own loop already holds while waiting on the LEDs. Reading a device or a plain variable is fine.

Member Enumeration Documentation

◆ SpliceRegionAnimKind

enum class hitlib::LedStrand::SpliceRegionAnimKind : uint8_t
strong

What a custom splice mask region shows.

OFF through BITSCROLL mirror the overlay*() animation vocabulary (see Overlay Animations), since each region gets a buffer built and animated the same way.

GAUGE animates from a reading rather than from a clock, making the region an independent meter. See GaugeStop and SpliceRegion's gauge fields.

Enumerator
OFF 
SOLID 
PULSE 
FLASH 
FLOW 
RAINBOW 
TWINKLE 
BITSCROLL 
GAUGE 

◆ GaugeStyle

enum class hitlib::LedStrand::GaugeStyle : uint8_t
strong

How a GAUGE region turns its level into pixels.

Enumerator
HEAT 

The whole region shows one color, picked off the scale.

BAR 

The region fills proportionally, like a miniature levelFill().

◆ GaugeBlend

enum class hitlib::LedStrand::GaugeBlend : uint8_t
strong

How a GAUGE region moves between two stops.

Enumerator
LERP 

Blend smoothly, so a rising reading slides between colors.

STEP 

Hold each stop's color until the next one is reached.

Constructor & Destructor Documentation

◆ LedStrand() [1/2]

hitlib::LedStrand::LedStrand ( uint8_t adiPort,
uint8_t length,
uint32_t refreshMs = 20 )

Construct a strand on a standard ADI port.

Parameters
adiPortADI port number (1–8).
lengthNumber of LEDs. Clamped to MAX_LEDS (64).
refreshMsRefresh interval in milliseconds (default 20 ms = 50 Hz).

◆ LedStrand() [2/2]

hitlib::LedStrand::LedStrand ( uint8_t smartPort,
uint8_t adiPort,
uint8_t length,
uint32_t refreshMs = 20 )

Construct a strand on an ADI expander port.

Parameters
smartPortSmart port the expander is connected to (1–21).
adiPortADI port on the expander (1–8).
lengthNumber of LEDs. Clamped to MAX_LEDS (64).
refreshMsRefresh interval in milliseconds (default 20 ms).

Member Function Documentation

◆ init()

void hitlib::LedStrand::init ( )

Initialize the hardware LED object.

Must be called from PROS initialize() (or before the first tick). Safe to call multiple times, subsequent calls are no-ops.

◆ tick()

void hitlib::LedStrand::tick ( )

Advance one animation frame.

Called automatically by LedGroup's internal task. Do not call this directly.

◆ off()

void hitlib::LedStrand::off ( )

Turn all LEDs off (set to black).

◆ setColor()

void hitlib::LedStrand::setColor ( uint32_t color)

Set all LEDs to a solid color.

Parameters
color24-bit RGB color (0xRRGGBB).

◆ pulse()

void hitlib::LedStrand::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.

Parameters
colorForeground color (0xRRGGBB).
runLengthNumber of lit pixels in the run.
speedPixels advanced per tick (1 = slowest).
bgColorBackground color (default black).
invertReverse the travel direction (default false).
bounceReverse direction at each end instead of wrapping (default false).

◆ flash()

void hitlib::LedStrand::flash ( uint32_t color,
uint32_t onMs,
uint32_t offMs,
uint32_t bgColor = 0x000000 )

Blink the whole strip on and off.

Every pixel lights at once for onMs, then the whole strip shows bgColor for offMs, and the cycle repeats. On and off times are independent, so rate and duty cycle are set separately.

Durations are rounded to whole refresh ticks and clamped to a minimum of one tick, so the strand can't be asked to blink faster than its refresh interval (see the refreshMs constructor parameter).

Parameters
colorLit color (0xRRGGBB).
onMsHow long the strip stays lit, in milliseconds.
offMsHow long the strip stays blank, in milliseconds.
bgColorBackground color shown while blank (default black).

◆ flow()

void hitlib::LedStrand::flow ( uint32_t color1,
uint32_t color2,
uint8_t speed,
bool invert = false,
bool seamless = true )

Scroll a two-color gradient across the strip.

Parameters
color1Start color (0xRRGGBB).
color2End color (0xRRGGBB).
speedPixels shifted per tick.
invertScroll in the reverse direction (default false).
seamlessLoop the gradient back to color1 instead of cutting straight from color2 to color1 at the wrap (default true).

◆ rainbow()

void hitlib::LedStrand::rainbow ( uint8_t speed)

Scroll a full HSV rainbow across the strip.

Parameters
speedPixels shifted per tick.

◆ twinkle()

void hitlib::LedStrand::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.

Each sparkle fades in to full brightness, holds briefly, then fades out. New sparkles are spawned at most one per tick to stagger phase offsets.

Parameters
colorsColor palette, one color is chosen at random per sparkle.
densityPctTarget percentage of LEDs simultaneously lit (0–100).
fadeStepBrightness step applied each tick (higher = faster fade).
bgColorBackground color shown on unlit pixels (default black).

◆ bitscroll()

void hitlib::LedStrand::bitscroll ( const std::vector< 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.

Parameters
segmentsList of BitScrollSegment descriptors defining the pattern.
speedPixels advanced per tick.
invertScroll in the reverse direction (default false).
bgColorColor shown between segments and in blank areas.
bounceRock the pattern back and forth instead of wrapping.
spacingGap pixels inserted between segments (default 5).
repeatingTile the pattern across the whole strip (true) or show a single copy of it (false). works for both wrapping and bounce travel.

◆ levelFill()

void hitlib::LedStrand::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.

Sets up the colors the meter fills with, then leaves the level itself alone, drive it with setLevel(). A meter starts empty, so nothing lights until the first setLevel() call.

With gradient the two colors are laid out across the whole strip, not across the lit part, so a given pixel is always the same color no matter how full the meter is (a VU meter that runs green at the bottom and red at the top, rather than a gradient that stretches). With gradient false only color is used.

The pixel at the edge of the fill is dimmed proportionally rather than snapping on, so a 30-LED strand shows a smooth ramp instead of 30 visible steps.

Calling this takes the meter back to manual control: any MusicTrack or levelSource() reader is detached, since either would overwrite whatever setLevel() puts there on the very next tick.

Parameters
colorFill color, and the gradient's start color (0xRRGGBB).
color2Gradient end color. Ignored unless gradient.
gradientBlend color to color2 across the strip.
bgColorColor shown on the unfilled part (default black).
invertFill from the far end of the strip instead of pixel 0.

◆ setLevel()

void hitlib::LedStrand::setLevel ( uint8_t level)

Set how full the meter is.

Cheap enough to call every control-loop iteration, it only stores a byte, the fill is computed at flush time. Detaches any MusicTrack or levelSource() reader, so manual updates aren't fighting one of those for the same meter.

Parameters
level0 = empty, 255 = the whole strip lit.

◆ getLevel()

uint8_t hitlib::LedStrand::getLevel ( ) const
inline

Return the meter's current level (0-255).

◆ levelSource()

void hitlib::LedStrand::levelSource ( 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.

The strand polls read once per refresh tick and maps what comes back onto the strip, so a gauge needs no code in your control loop: set it up once (in initialize(), or in a ProfileMode's onActivate) and the bar tracks the value from then on.

Units are yours to choose, emptyAt and fullAt are given in whatever the reader returns:

pros::Motor intake(11);
strand.levelFill(0x00FF00, 0xFF0000, true); // green -> red scale
strand.levelSource([] { return intake.get_temperature(); },
20.0, 70.0); // cool -> shutdown hot
// A battery gauge that empties as the battery does:
strand.levelSource([] { return pros::battery::get_capacity(); }, 0.0, 100.0);
// A bar that fills once per revolution and starts over:
strand.levelSource([] { return arm.get_position(); }, 0.0, 360.0, true);

Values outside the range clamp to empty or full. With wrap they cycle instead, for a continuously turning motor or a heading: 450° of a 0-360 range shows the bar a quarter full, not full.

Putting fullAt below emptyAt is allowed and reverses the meter, so a "distance remaining" bar that drains as a number climbs needs no arithmetic of its own.

This keeps the colors from the preceding levelFill(), it only changes what drives the fill, so call levelFill() first. Any MusicTrack is detached.

Parameters
readValue to follow. nullptr clears the source, so exported code can name a hook before it is assigned.
emptyAtReading that shows an empty strip.
fullAtReading that shows a full one.
wrapCycle back to empty past fullAt instead of clamping.
smoothing0-99. How much of the previous frame's fill to keep each tick: 0 follows the value exactly, higher glides toward it, for noisy readings (motor velocity, current draw). The bar still reaches its target, over a few ticks.

◆ clearLevelSource()

void hitlib::LedStrand::clearLevelSource ( )

Stop following a levelSource() reader, leaving the fill where it is.

The meter stays set up and keeps its colors, it just stops moving on its own, so setLevel() takes over cleanly from here.

◆ levelSourceActive()

bool hitlib::LedStrand::levelSourceActive ( ) const
inline

Whether a levelSource() reader is currently driving the meter.

◆ musicSync()

void hitlib::LedStrand::musicSync ( const 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.

Playback is anchored to the wall clock at the moment of this call, so call it when the music starts, typically from a ProfileMode's onActivate. The strand then tracks the song on its own with no further calls, samples are interpolated between frames so the fill stays smooth even when the envelope's frame rate is coarser than refreshMs.

Colors, gradient and invert behave exactly as in levelFill(). Any levelSource() reader is detached, the song drives the meter now.

Parameters
trackEnvelope to play. Must outlive the strand.
colorFill color, and the gradient's start color.
color2Gradient end color. Ignored unless gradient.
gradientBlend color to color2 across the strip.
bgColorColor shown on the unfilled part.
invertFill from the far end of the strip.
sensitivityGain applied to every sample, as a percentage. 100 = the envelope as baked, higher makes quiet passages reach further up the strip (and clips loud ones at full), lower makes it more selective.
loopRestart from the top when the song ends instead of going dark.

◆ musicSeek()

void hitlib::LedStrand::musicSeek ( uint32_t positionMs)

Jump playback to a position in the song.

Parameters
positionMsOffset from the start of the track, in milliseconds.

◆ musicPause()

void hitlib::LedStrand::musicPause ( bool paused = true)

Pause or resume playback, holding the meter where it is.

Parameters
pausedtrue to pause, false to resume.

◆ musicPlaying()

bool hitlib::LedStrand::musicPlaying ( ) const
inline

Whether a MusicTrack is attached and not paused.

◆ musicPositionMs()

uint32_t hitlib::LedStrand::musicPositionMs ( ) const

Current playback position in milliseconds.

◆ setSensitivity()

void hitlib::LedStrand::setSensitivity ( uint8_t pct)

Change the gain applied to envelope samples without restarting.

Parameters
pctPercentage gain, see musicSync()'s sensitivity.

◆ spliceMask()

void hitlib::LedStrand::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.

The strip is divided into sections + 1 equal bins. Even-indexed bins (or their complement when invert is true) show bgColor, or the overlay buffer when useOverlay is true, instead of the active base animation.

Parameters
sectionsNumber of divider boundaries (e.g. 1 = two halves). Pass 0 to disable.
invertSwap which bins are overridden (default false).
alternatingToggle invert automatically every altPeriodMs.
altPeriodMsToggle period when alternating is true (ms).
bgColorColor shown in masked bins when useOverlay is false.
useOverlayShow the overlay buffer in masked bins instead of bgColor.

◆ spliceMaskCustom()

void hitlib::LedStrand::spliceMaskCustom ( const std::vector< SpliceRegion > & regions)

Apply a splice mask made of independently placed/sized regions, each running its own animation.

Unlike spliceMask(), regions can start and end anywhere on the strip, don't alternate, and each gets a dedicated buffer generated over just its own width. So e.g. one region can rainbow-scroll while another pulses, simultaneously. Regions stay fixed until spliceMaskCustom() or clearSpliceMask() is called again. Later entries win where regions overlap.

A GAUGE region is the same idea pointed at a sensor instead of a clock: it polls its own reader every tick and colors itself off its own scale, so one strip can carry several independent meters. The strand-wide levelFill() meter is limited to one per strand.

// Six motors, six segments of a 60-LED strip under the drivebase, each
// colored by how hot its own motor is.
pros::Motor drive[6] = {...};
std::vector<LedStrand::SpliceRegion> regions;
for (uint8_t i = 0; i < 6; ++i) {
regions.push_back(LedStrand::motorHeatGauge(i * 10, 9, readers[i]));
}
strand.spliceMaskCustom(regions);
static SpliceRegion motorHeatGauge(uint8_t start, uint8_t width, LevelFn read=nullptr)
A GAUGE region pre-loaded with the V5 motor's own heat schedule.
Parameters
regionsOverride regions to apply.

◆ setRegionLevel()

void hitlib::LedStrand::setRegionLevel ( uint8_t regionIdx,
uint8_t level )

Set how full a hand-driven GAUGE region is.

The counterpart of setLevel() for one region rather than the whole strand, for gauges whose SpliceRegion left read as nullptr. Cheap enough to call every control-loop iteration: it stores a byte, and the region repaints at flush time.

Ignored for a region that has a reader of its own, which would overwrite it on the very next tick anyway.

Parameters
regionIdxIndex into the vector last handed to spliceMaskCustom().
level0 = the bottom of the region's scale, 255 = the top.

◆ motorHeatGauge()

SpliceRegion hitlib::LedStrand::motorHeatGauge ( uint8_t start,
uint8_t width,
LevelFn read = nullptr )
static

A GAUGE region pre-loaded with the V5 motor's own heat schedule.

The stops are the temperatures the motor itself changes behaviour at, so the colors mean something specific rather than being a pretty ramp:

Reading Color What the motor is doing
20 °C green cold, full power
45 °C yellow warm, nearing the first cut
55 °C orange current limited to 50%
60 °C red current limited to 25%
65 °C deep red current limited to 12.5%
70 °C magenta shut down

Magenta at the top is deliberate - it is the one color on the scale that cannot be mistaken for "a bit hotter than the last one".

The returned region is an ordinary SpliceRegion, so anything about it can be overridden before it is handed to spliceMaskCustom().

Parameters
startFirst pixel of the segment.
widthNumber of pixels in it.
readReader returning a motor temperature in °C. nullptr leaves the segment driven by setRegionLevel().

◆ clearSpliceMask()

void hitlib::LedStrand::clearSpliceMask ( )

Remove the active splice mask, whichever kind is active.

◆ overlaySetColor()

void hitlib::LedStrand::overlaySetColor ( uint32_t color)

Set the overlay buffer to a solid color.

◆ overlayPulse()

void hitlib::LedStrand::overlayPulse ( uint32_t color,
uint8_t runLength,
uint8_t speed,
uint32_t bgColor = 0x000000 )

Animate a moving run in the overlay buffer.

◆ overlayFlash()

void hitlib::LedStrand::overlayFlash ( uint32_t color,
uint32_t onMs,
uint32_t offMs,
uint32_t bgColor = 0x000000 )

Blink the overlay buffer on and off (see flash()).

◆ overlayFlow()

void hitlib::LedStrand::overlayFlow ( uint32_t color1,
uint32_t color2,
uint8_t speed,
bool seamless = true )

Scroll a gradient in the overlay buffer.

Parameters
seamlessLoop the gradient back to color1 instead of cutting straight from color2 to color1 at the wrap (default true). See flow().

◆ overlayRainbow()

void hitlib::LedStrand::overlayRainbow ( uint8_t speed)

Scroll a rainbow in the overlay buffer.

◆ overlayTwinkle()

void hitlib::LedStrand::overlayTwinkle ( const std::vector< uint32_t > & colors,
uint8_t densityPct = 30,
uint8_t fadeStep = 16,
uint32_t bgColor = 0x000000 )

Sparkle random pixels of the overlay buffer (see twinkle()).

◆ overlayBitscroll()

void hitlib::LedStrand::overlayBitscroll ( const std::vector< BitScrollSegment > & segments,
uint8_t speed,
bool invert = false,
uint32_t bgColor = 0x000000,
uint8_t spacing = 5,
bool repeating = true )

Scroll a repeating bit pattern in the overlay buffer (see bitscroll()).

No bounce: the overlay is a single scrolling buffer, and bouncing needs a wider master pattern to slide a window over. Use the base animation for that.

◆ setBrightness()

void hitlib::LedStrand::setBrightness ( uint8_t pct)

Set global brightness for this strand.

Applied non-destructively at flush time, the animation buffers are not modified. Does not require the strand to be re-initialized.

Parameters
pctBrightness percentage (0 = off, 100 = full). Clamped to [0, 100].

◆ getBrightness()

uint8_t hitlib::LedStrand::getBrightness ( ) const
inline

Return the current brightness percentage.

◆ attachProfile()

void hitlib::LedStrand::attachProfile ( const Profile * profile)

Attach a Profile and reset the mode stack.

Parameters
profilePointer to a statically-allocated Profile. Must remain valid for the lifetime of the attachment.

◆ detachProfile()

void hitlib::LedStrand::detachProfile ( )

Detach the active profile and turn the strand off.

◆ activateMode()

void hitlib::LedStrand::activateMode ( uint8_t modeIdx)

Push a persistent mode onto the mode stack.

The mode remains active until explicitly removed with deactivateMode(). Calling this for an already-active persistent mode is a no-op.

Parameters
modeIdxIndex into the attached profile's modes array.

◆ activateModeTimed()

void hitlib::LedStrand::activateModeTimed ( uint8_t modeIdx,
uint32_t durationMs )

Push a timed mode onto the mode stack.

The mode auto-expires after durationMs milliseconds. If the mode is already active (as a timed entry), its deadline is extended rather than creating a duplicate.

Parameters
modeIdxIndex into the attached profile's modes array.
durationMsHow long the mode stays active (milliseconds).

◆ deactivateMode()

void hitlib::LedStrand::deactivateMode ( uint8_t modeIdx)

Remove a mode from the stack immediately.

Parameters
modeIdxIndex of the mode to remove.

◆ getLength()

uint8_t hitlib::LedStrand::getLength ( ) const
inline

Return the number of LEDs in this strand.

Member Data Documentation

◆ MAX_LEDS

uint8_t hitlib::LedStrand::MAX_LEDS
staticconstexpr