Class SpectrumLEDs
- All Implemented Interfaces:
Subsystem
- Direct Known Subclasses:
Leds
Patterns come in two flavors. Hardware animations (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()) run in the CANdle's firmware and cost nothing per loop. 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)) send a one-shot SolidColor that is resent every
loop, and switching to one of them clears the running animations.
Several instances can share one physical CANdle by passing the same device to their
SpectrumLEDs.Config and taking non-overlapping startIdx and numLeds ranges, each with
its own animation slot.
setPattern(CANdlePattern, int) returns a Command that applies the pattern for
as long as it runs and holds the priority it was given (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 CANdleTheCANdlethis instance drives, either owned or shared.protected final CommandThe default command, which displaysdefaultPatternat the lowest priority.protected final SpectrumLEDs.CANdlePatternPattern shown when no other command wants this subsystem (an orange blink).final TriggerActive while the installed default command is the one running, which means no higher-priority pattern owns the subsystem.final ColorSpectrum purple color constant (RGB 130, 103, 185).final ColorConvenience alias forColor.kWhite. -
Constructor Summary
ConstructorsConstructorDescriptionSpectrumLEDs(SpectrumLEDs.Config config) Configures the hardware (or reuses a shared device) and registers with the WPILibCommandScheduler. -
Method Summary
Modifier and TypeMethodDescriptionBlinks betweencolorand off.Bouncing dot that travels back and forth along the strip.Fades betweencolorand off and back, overperiodSecs.Lights one LED at a time across the strip and repeats.checkPriority(int priority) Returns a trigger that is true while the running pattern command's priority is at or belowpriority, for gating a lower-priority pattern out of the way of a higher-priority one.countdown(DoubleSupplier countStartTimeSec, double durationInSeconds) Counts down by turning LEDs off from the end of the segment toward the start, while the color fades from yellow to red.Lights the first and lastlengthLEDs withcolorand turns the middle off, with two or threeSolidColorcontrols.fire()Fire animation from the CANdle's own animation engine.TheCANdlethis instance drives, either owned or shared.intPriority of the pattern command currently running;setPattern(CANdlePattern, int)stores this while a command runs and resets it to-1when the command ends.Name of the command currently applying a pattern, or "None" when none is running.Linear gradient fromcolor1tocolor2across the segment, oneSolidColorper LED, computed at first use.booleanTrue when the most recently applied pattern was a hardware animation running in firmware, false when it was a softwareSolidColorpattern.booleanOmbre that blends between the two colors and scrolls the blend point along the strip over time.rainbow()Rainbow advancing slowly across the strip.rainbow(double brightness) Rainbow advancing slowly across the strip, at the given brightness.rgbCycle()RGB color cycle from the CANdle's own animation engine.Rainbow advancing quickly across the strip.voidsetCommandPriority(int commandPriority) Priority of the pattern command currently running;setPattern(CANdlePattern, int)stores this while a command runs and resets it to-1when the command ends.setPattern(SpectrumLEDs.CANdlePattern pattern) setPattern(CANdlePattern, int)at priority 0.setPattern(SpectrumLEDs.CANdlePattern pattern, int priority) Returns a command that appliespatternto the segment for as long as it runs and holdsprioritywhile it does.Solid color, from a singleSolidColorcontrol request resent each loop.Two-color stripe: the firstpercentfraction of LEDs showscolor1and the rest showscolor2, sent as twoSolidColorcontrols.switchCountdown(Color startingColor) Alliance switch countdown.Sine wave blending between the two colors, oneSolidColorper LED.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
TheCANdlethis instance drives, either owned or shared. -
defaultPattern
Pattern shown when no other command wants this subsystem (an orange blink). Built in the constructor body, afterconfigis set, so the factory can read the config. -
defaultCommand
The default command, which displaysdefaultPatternat the lowest priority. A subclass can install its own default command to replace it; query the installed one withSubsystem.getDefaultCommand(). -
defaultTrigger
Active while the installed default command is the one running, which means no higher-priority pattern owns the subsystem. -
purple
Spectrum purple color constant (RGB 130, 103, 185). -
white
Convenience alias forColor.kWhite.
-
-
Constructor Details
-
SpectrumLEDs
Configures the hardware (or reuses a shared device) and registers with the WPILibCommandScheduler.- Parameters:
config- device, segment range, and strip type for this instance
-
-
Method Details
-
isAttached
public boolean isAttached() -
isAnimating
public boolean isAnimating()True when the most recently applied pattern was a hardware animation running in firmware, false when it was a softwareSolidColorpattern. -
getCurrentCommandName
Name of the command currently applying a pattern, or "None" when none is running. -
checkPriority
Returns a trigger that is true while the running pattern command's priority is at or belowpriority, for gating a lower-priority pattern out of the way of a higher-priority one. -
setPattern
Returns a command that appliespatternto the segment for as long as it runs and holdsprioritywhile it does. The command runs while the robot is disabled.Switching from a hardware animation to a software
SolidColorpattern clears the active animation slots before the first software write.- Parameters:
pattern- pattern to apply each loop cyclepriority- priority level to hold incommandPrioritywhile this command runs- Returns:
- a command that applies the pattern continuously
-
setPattern
setPattern(CANdlePattern, int)at priority 0. -
blink
Blinks betweencolorand off. Each half-cycle, on and off, lastsonTimeSecsseconds, so the frame rate is one over that.- Parameters:
color- the blink coloronTimeSecs- seconds per on or off half-cycle- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
breathe
Fades betweencolorand off and back, overperiodSecs. Each animation frame moves brightness by 1%, so a full cycle needs 200 frames and the frame rate is 200 over the period.- Parameters:
color- the peak color at full brightnessperiodSecs- seconds for one full breathe cycle- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
rainbow
Rainbow advancing slowly across the strip. -
rainbow
Rainbow advancing slowly across the strip, at the given brightness.- Parameters:
brightness- brightness scalar, 0.0-1.0
-
scrollingRainbow
Rainbow advancing quickly across the strip. -
chase
Lights one LED at a time across the strip and repeats. The frame rate isnumLeds * speed, sospeedfull cycles happen per second.- Parameters:
color- the chase colorspeed- desired full strip cycles per second- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
bounce
Bouncing dot that travels back and forth along the strip.- Parameters:
color- the dot colordurationSecs- seconds for one complete back-and-forth cycle- Returns:
- a hardware animation
SpectrumLEDs.CANdlePattern
-
fire
Fire animation from the CANdle's own animation engine. -
rgbCycle
RGB color cycle from the CANdle's own animation engine. -
solid
Solid color, from a singleSolidColorcontrol request 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 showscolor1and the rest showscolor2, sent as twoSolidColorcontrols.- 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 fromcolor1tocolor2across the segment, oneSolidColorper LED, computed at first use.- 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
Lights the first and lastlengthLEDs withcolorand turns the middle off, with two or threeSolidColorcontrols.- 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
Ombre that blends between the two colors and scrolls the blend point along the strip over time. The colors are rebuilt every loop becauseRGBWColoris immutable.- Parameters:
startColor- the leading colorendColor- the trailing color- Returns:
- a software
SpectrumLEDs.CANdlePatternshowing the animated ombre
-
wave
Sine wave blending between the two colors, oneSolidColorper LED.- 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) Counts down by turning LEDs off from the end of the segment toward the start, while the color fades from yellow to red.- 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. Colors follow a hard-coded match-time schedule, and LEDs turn off within each segment as its time runs out.Seconds remaining, and the color shown:
140-130 purple 130-105 startingColor 105-80 opponent color 80-55 startingColor 55-30 opponent color 30-0 purple
- Parameters:
startingColor- the alliance color shown during this robot's segments- Returns:
- a software
SpectrumLEDs.CANdlePatternreflecting the current switch-countdown state
-
getConfig
-
getCandle
TheCANdlethis instance drives, either owned or shared. -
getCommandPriority
public int getCommandPriority()Priority of the pattern command currently running;setPattern(CANdlePattern, int)stores this while a command runs and resets it to-1when the command ends. -
setCommandPriority
public void setCommandPriority(int commandPriority) Priority of the pattern command currently running;setPattern(CANdlePattern, int)stores this while a command runs and resets it to-1when the command ends.
-