Class SpectrumLEDs
- All Implemented Interfaces:
Subsystem
- Direct Known Subclasses:
Leds
CANdle and exposes a rich
library of pattern factories (solid, stripe, blink, breathe, rainbow, chase, bounce, gradient,
ombre, wave, countdown, etc.).
Patterns are split into two categories:
- Hardware animation patterns (
blink(edu.wpi.first.wpilibj.util.Color, double),breathe(edu.wpi.first.wpilibj.util.Color, double),rainbow(),scrollingRainbow(),chase(edu.wpi.first.wpilibj.util.Color, double),bounce(edu.wpi.first.wpilibj.util.Color, double),fire(),rgbCycle()) — these usesetControl()with CANdle's built-in animation engine. They run autonomously in firmware and require no per-loop CPU work. - Software patterns (
solid(edu.wpi.first.wpilibj.util.Color),stripe(double, edu.wpi.first.wpilibj.util.Color, edu.wpi.first.wpilibj.util.Color),gradient(edu.wpi.first.wpilibj.util.Color, edu.wpi.first.wpilibj.util.Color),ombre(edu.wpi.first.wpilibj.util.Color, edu.wpi.first.wpilibj.util.Color),wave(edu.wpi.first.wpilibj.util.Color, edu.wpi.first.wpilibj.util.Color, double, double),countdown(java.util.function.DoubleSupplier, double),switchCountdown(edu.wpi.first.wpilibj.util.Color),edges(edu.wpi.first.wpilibj.util.Color, int)) — these usesetControl(SolidColor)which is a one-shot command resent each loop. When switching from a hardware animation to a software pattern, all animations are automatically cleared.
Multiple SpectrumLEDs instances can share a single physical CANdle device by
passing the same CANdle reference in their SpectrumLEDs.Config objects and selecting
non-overlapping startIdx/numLeds ranges.
Patterns are applied via setPattern(CANdlePattern, int), which returns a Command that runs continuously and respects the priority system (checkPriority(int)).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for a LED pattern that drives a segment of aCANdlestrip.static classConfiguration for aSpectrumLEDssubsystem instance. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CANdleTheCANdledevice (owned or shared).protected final CommandThe default command built by this class (displaysdefaultPatternat lowest priority).protected final SpectrumLEDs.CANdlePatternDefault pattern shown when no other command requires this subsystem (orange blink).final TriggerTrigger that is active while the currently installed default command (whichever one that is) is the one running — i.e.final ColorSpectrum purple color constant (RGB 130, 103, 185).final ColorConvenience alias forColor.kWhite. -
Constructor Summary
ConstructorsConstructorDescriptionSpectrumLEDs(SpectrumLEDs.Config config) Constructs the LED subsystem, configures the hardware (or reuses a shared device), and registers with the WPILibCommandScheduler. -
Method Summary
Modifier and TypeMethodDescriptionBlinking (strobe) pattern — alternates betweencolorand off.Bouncing dot pattern — a pocket of light travels back and forth across the strip.Breathing (sinusoidal fade-in/out) pattern — fades between the peakcolorand off.Chase / color-flow pattern — progressively lights LEDs one at a time across the strip and repeats.checkPriority(int priority) Returns aTriggerthat is active when the currently running command's priority is at or below the given value.countdown(DoubleSupplier countStartTimeSec, double durationInSeconds) Countdown pattern — LEDs transition from yellow to red and progressively turn off from the end of the segment toward the beginning as time elapses.Edge-highlight pattern — lights the first and lastlengthLEDs withcolorand turns off the center LEDs.fire()Fire animation using the CANdle's built-in hardware animation engine.TheCANdledevice (owned or shared).intPriority level of the pattern command currently running.Active configuration for this instance.Returns the currently running command that is applying a pattern to this subsystem, ornullif no command is currently running.Linear gradient between two colors across the strip.booleanReturnstrueif the most recently applied pattern was a CANdle hardware animation running in firmware,falseif it was a softwareSolidColorpattern.booleanReturns whether this LED strip is physically connected to the robot.Animated ombre — transitions smoothly between two colors across the strip and scrolls the blend point over time.rainbow()Static rainbow — hue distributed evenly across the strip, advancing very slowly.rainbow(double brightness) Static rainbow with configurable brightness.rgbCycle()RGB color-cycle animation using the CANdle's built-in hardware animation engine.Scrolling rainbow that advances quickly across the strip.voidsetCommandPriority(int commandPriority) Priority level of the pattern command currently running.setPattern(SpectrumLEDs.CANdlePattern pattern) Returns a command that continuously appliespatternto the LED segment at priority 0.setPattern(SpectrumLEDs.CANdlePattern pattern, int priority) Returns a command that continuously appliespatternto the LED segment and records the givenprioritywhile running.Solid color pattern.Two-color stripe: the firstpercentfraction of LEDs showscolor1, the remainder showscolor2.switchCountdown(Color startingColor) Alliance switch countdown — cycles through alliance colors (and purple) on a hard-coded match-time schedule, progressively turning off LEDs within each segment as time elapses.Sinusoidal wave pattern blending between two colors.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, getName, idle, periodic, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Field Details
-
candle
TheCANdledevice (owned or shared). -
defaultPattern
Default pattern shown when no other command requires this subsystem (orange blink).Initialized in the constructor body (after
configis set) so that pattern factories can safely reference the config. -
defaultCommand
The default command built by this class (displaysdefaultPatternat lowest priority). Installed viasetDefaultCommandin the constructor; subclasses may install their own default command to replace it. UsegetDefaultCommand()(fromSubsystem) to query whichever default is currently installed. -
defaultTrigger
Trigger that is active while the currently installed default command (whichever one that is) is the one running — i.e. no higher-priority pattern owns the subsystem. -
purple
Spectrum purple color constant (RGB 130, 103, 185). -
white
Convenience alias forColor.kWhite.
-
-
Constructor Details
-
SpectrumLEDs
Constructs the LED subsystem, configures the hardware (or reuses a shared device), and registers with the WPILibCommandScheduler.- Parameters:
config- the configuration describing the device, segment range, and strip type
-
-
Method Details
-
isAttached
public boolean isAttached()Returns whether this LED strip is physically connected to the robot.- Returns:
trueif attached
-
isAnimating
public boolean isAnimating()Returnstrueif the most recently applied pattern was a CANdle hardware animation running in firmware,falseif it was a softwareSolidColorpattern. -
getCurrentCommandName
Returns the currently running command that is applying a pattern to this subsystem, ornullif no command is currently running.- Returns:
- the currently running command, or
nullif none
-
checkPriority
Returns aTriggerthat is active when the currently running command's priority is at or below the given value. Use to gate lower-priority commands from overriding higher-priority ones.- Parameters:
priority- the maximum priority level that allows the trigger to be active- Returns:
- trigger active when
commandPriority≤ priority
-
setPattern
Returns a command that continuously appliespatternto the LED segment and records the givenprioritywhile running. The command runs while the robot is disabled.When switching from a hardware animation to a software (
SolidColor) pattern, all active animation slots are cleared automatically before the first software write.- Parameters:
pattern- theSpectrumLEDs.CANdlePatternto apply each loop cyclepriority- priority level stored incommandPrioritywhile this command runs- Returns:
- a command that applies the pattern continuously
-
setPattern
Returns a command that continuously appliespatternto the LED segment at priority 0.- Parameters:
pattern- theSpectrumLEDs.CANdlePatternto apply- Returns:
- a command that applies the pattern continuously at the default priority
-
blink
Blinking (strobe) pattern — alternates betweencolorand off. Each half-cycle (on and off) lastsonTimeSecsseconds.Implemented using
StrobeAnimation. Frame rate =1 / onTimeSecsHz.- Parameters:
color- the blink coloronTimeSecs- duration in seconds of each on (and off) half-cycle- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
breathe
Breathing (sinusoidal fade-in/out) pattern — fades between the peakcolorand off.Implemented using
SingleFadeAnimation. Each animation frame changes brightness by 1%, so frame rate =200 / periodSecsHz for a complete 0→100→0% cycle.- Parameters:
color- the peak color at full brightnessperiodSecs- duration in seconds of one full breathe cycle- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
rainbow
Static rainbow — hue distributed evenly across the strip, advancing very slowly.- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
rainbow
Static rainbow with configurable brightness.- Parameters:
brightness- brightness scalar (0.0–1.0)- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
scrollingRainbow
Scrolling rainbow that advances quickly across the strip.- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
chase
Chase / color-flow pattern — progressively lights LEDs one at a time across the strip and repeats.Implemented using
ColorFlowAnimation. Frame rate =numLeds × speedHz so thatspeedfull cycles occur per second.- Parameters:
color- the chase colorspeed- desired number of full strip cycles per second- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
bounce
Bouncing dot pattern — a pocket of light travels back and forth across the strip.Implemented using
LarsonAnimationwithLarsonBounceValue.Back. Frame rate is computed so one back-and-forth cycle takesdurationSecsseconds.- Parameters:
color- the dot colordurationSecs- seconds per complete back-and-forth cycle- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
fire
Fire animation using the CANdle's built-in hardware animation engine.- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
rgbCycle
RGB color-cycle animation using the CANdle's built-in hardware animation engine.- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
solid
Solid color pattern.Uses a single
SolidColorcontrol request (one-shot, resent each loop).- Parameters:
color- the color to display- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing a constant solid color
-
stripe
Two-color stripe: the firstpercentfraction of LEDs showscolor1, the remainder showscolor2.Uses two
SolidColorcontrols (one-shot each, resent each loop).- Parameters:
percent- fraction of the strip (0.0–1.0) assigned tocolor1color1- color for the leading segmentcolor2- color for the trailing segment- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing the two-color stripe
-
gradient
Linear gradient between two colors across the strip. Colors are pre-computed at first use.Uses N
SolidColorcontrols (one per LED, one-shot, resent each loop).- Parameters:
color1- color at the start (index 0) of the segmentcolor2- color at the end of the segment- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing the two-color gradient
-
edges
Edge-highlight pattern — lights the first and lastlengthLEDs withcolorand turns off the center LEDs.Uses two or three
SolidColorcontrols (one-shot, resent each loop).- Parameters:
color- the color to apply to the edge LEDslength- the number of LEDs to illuminate at each end of the strip- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing lit edges and a dark center
-
ombre
Animated ombre — transitions smoothly between two colors across the strip and scrolls the blend point over time.Uses N
SolidColorcontrols (one per LED, one-shot, resent each loop with updated colors).RGBWColorobjects are created each loop since the type is immutable.- Parameters:
startColor- the leading colorendColor- the trailing color- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing the animated ombre
-
wave
Sinusoidal wave pattern blending between two colors.Uses N
SolidColorcontrols (one per LED, one-shot, resent each loop).- Parameters:
c1- first wave colorc2- second wave colorcycleLength- number of LEDs per wave perioddurationSecs- period of the time-based animation in seconds- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing the wave
-
countdown
public SpectrumLEDs.CANdlePattern countdown(DoubleSupplier countStartTimeSec, double durationInSeconds) Countdown pattern — LEDs transition from yellow to red and progressively turn off from the end of the segment toward the beginning as time elapses.Uses N
SolidColorcontrols (one per LED, one-shot, resent each loop).- Parameters:
countStartTimeSec- supplies the FPGA timestamp (seconds) when the countdown begandurationInSeconds- total countdown duration in seconds- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing the countdown
-
switchCountdown
Alliance switch countdown — cycles through alliance colors (and purple) on a hard-coded match-time schedule, progressively turning off LEDs within each segment as time elapses.Segment schedule (seconds remaining → color):
140–130 purple 130–105 startingColor 105–80 opponent color 80–55 startingColor 55–30 opponent color 30–0 purple
Uses N
SolidColorcontrols (one per LED, one-shot, resent each loop).- Parameters:
startingColor- the alliance color displayed during this robot's segments- Returns:
- a software
SpectrumLEDs.CANdlePatternreflecting the current switch-countdown state
-
getConfig
Active configuration for this instance. -
getCandle
TheCANdledevice (owned or shared). -
getCommandPriority
public int getCommandPriority()Priority level of the pattern command currently running. Higher values indicate higher priority;setPattern(CANdlePattern, int)stores this while a command runs and resets it to-1when the command ends. -
setCommandPriority
public void setCommandPriority(int commandPriority) Priority level of the pattern command currently running. Higher values indicate higher priority;setPattern(CANdlePattern, int)stores this while a command runs and resets it to-1when the command ends.
-