Class Lights
- All Implemented Interfaces:
Subsystem
lights = add(Lights.gobilda("light")); // Robot.java: a goBILDA RGB Indicator Light (a servo port)
// Controls.java, in buttons(...): a flash first (it beats every rule while it lasts), then the most
// important rule first
robot.lights.show(LightColor.WHITE).whenCountGoesUp(() -> robot.launcher.part().getShotsFired()); // a 0.5 s flash per shot
robot.lights.show(LightColor.YELLOW).blinking().inLastSeconds(20); // time to park
robot.lights.show(LightColor.GREEN).when(robot.launcher::isReady); // at speed: fire
robot.lights.show(LightColor.PURPLE).when(() -> robot.turret.followMode().isOn());
robot.lights.otherwise(LightColor.OFF); // when no rule is true
- First true rule wins: rules are checked in the order you wrote them. Put the most important one first.
- A flash beats every rule while it lasts (
flash(LightColor)from a button or an action, orLights.Rule.whenStarts(java.util.function.BooleanSupplier)orLights.Rule.whenCountGoesUp(java.util.function.IntSupplier)). - Never waits: blinking and flashes are worked out from the clock each loop.
- Any true/false works as a rule: a part's method (
robot.intake::isRunning), aMode(() -> robot.turret.followMode().isOn()), or your own (() -> robot.lift.position() > 1000). - Actions do not "claim" the light (see
Action): anything may flash it at any time.
The alliance at INIT (on by default): before START the light shows the alliance the drivers
chose, solid RED or BLUE, so a wrong pick is seen before the match; until one is
chosen it blinks white once a second ("choose the alliance"). At START it flashes the alliance for
1 s (TeleOp after autonomous: the alliance it got), and again when the alliance is switched during
TeleOp. Then your rules take over. Off: allianceAtInit = false in this light's Tunables
section, or allianceAtInit(boolean). Other colors: allianceColors(com.crossbotics.ftchelper.robot.LightColor, com.crossbotics.ftchelper.robot.LightColor); a Blinkin
pattern of your own for a color: blinkinPattern(com.crossbotics.ftchelper.robot.LightColor, com.qualcomm.hardware.rev.RevBlinkinLedDriver.BlinkinPattern).
Game rules (FTC 2026-27 manual, R202 J and F): lights that flash faster than 5 times a second, or
very bright lights, can be turned off by the referees. So Lights.Rule.blinking(double) stops at 5,
and the light never changes color twice within MIN_CHANGE_SEC (0.1 s), whatever the rules,
flashes and blinking ask: a rule that turns on and off every loop, or flash after flash, still
switches the light at most 5 times on and off a second. A light in the alliance's color is allowed
(no rule against it); the ROBOT SIGNS must still show the alliance color (R402). Keep your other
rules' colors away from red and blue, so nobody reads them as the alliance.
Docs: docs/modules/robot.md (section "Lights")
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleHow long the alliance color flashes at START and when the alliance is switched, seconds.static final doubleBlinks per second when none is given.static final doubleBlinks per second of "choose the alliance" in INIT (slow: well under the 5 per second limit).static final doubleA flash's length when none is given: half a second.static final doubleThe most blinks per second allowed (FTC R202 J: faster than 5 per second invites the referees).static final doubleThe shortest time between two color changes, seconds: 0.1 s, so the light switches on and off at most 5 times a second (FTC R202 J) even when a rule changes every loop. -
Method Summary
Modifier and TypeMethodDescriptionvoidThe part's telemetry line; each module adds its own.allianceAtInit(boolean on) The alliance at INIT on or off (on by default; see the class comment).allianceColors(LightColor blue, LightColor red) The colors for the alliance at INIT, if your light shows red or blue badly.static LightsA REV Blinkin LED Driver (REV-11-1105) on a servo port, driving an LED strip (5 V addressable or 12 V).blinkinPattern(LightColor color, com.qualcomm.hardware.rev.RevBlinkinLedDriver.BlinkinPattern pattern) A REV Blinkin only: show this pattern for this color (e.g.voidTakes away every rule (the "otherwise" color stays).color()The color the rules pick now (a blinking color counts even in its dark half).voidflash(LightColor color) Flashes a color now for half a second, over every rule: from a button (g2.a.press(() -> robot.lights.flash(LightColor.WHITE))) or at the end of an action (.then(() -> r.lights.flash(LightColor.GREEN))).voidflash(LightColor color, double seconds) Flashes a color now for this long, over every rule.static LightsA goBILDA RGB Indicator Light (3118-0808-0002), plugged into a servo port.booleanTrue while a flash is showing.otherwise(LightColor color) The color when no rule is true (OFF if you never say).show(LightColor color) Starts a rule: the color to show.showing()What the light shows right now: OFF in a blink's dark half.booleanTrue while the light shows the alliance in INIT (not turned off).voidstop()Stops all motion.voidupdate()Called once every loop.
-
Field Details
-
FLASH_SEC
public static final double FLASH_SECA flash's length when none is given: half a second.- See Also:
-
BLINK_HZ
public static final double BLINK_HZBlinks per second when none is given.- See Also:
-
MAX_BLINK_HZ
public static final double MAX_BLINK_HZThe most blinks per second allowed (FTC R202 J: faster than 5 per second invites the referees).- See Also:
-
MIN_CHANGE_SEC
public static final double MIN_CHANGE_SECThe shortest time between two color changes, seconds: 0.1 s, so the light switches on and off at most 5 times a second (FTC R202 J) even when a rule changes every loop. A change asked for sooner waits (a flash shorter than this may not show at all).- See Also:
-
ALLIANCE_FLASH_SEC
public static final double ALLIANCE_FLASH_SECHow long the alliance color flashes at START and when the alliance is switched, seconds.- See Also:
-
CHOOSE_HZ
public static final double CHOOSE_HZBlinks per second of "choose the alliance" in INIT (slow: well under the 5 per second limit).- See Also:
-
-
Method Details
-
gobilda
A goBILDA RGB Indicator Light (3118-0808-0002), plugged into a servo port. In the robot configuration it is a "Servo". Several lights chained on one cable show the same color.- Parameters:
servoName- its configuration name, e.g. "light"
-
blinkin
A REV Blinkin LED Driver (REV-11-1105) on a servo port, driving an LED strip (5 V addressable or 12 V). In the robot configuration it is a "REV Blinkin LED Driver".- Parameters:
name- its configuration name, e.g. "blinkin"
-
show
Starts a rule: the color to show. Finish it withLights.Rule.when(java.util.function.BooleanSupplier),Lights.Rule.whenStarts(java.util.function.BooleanSupplier),Lights.Rule.whenCountGoesUp(java.util.function.IntSupplier)orLights.Rule.inLastSeconds(double).- Parameters:
color- e.g.LightColor.GREEN- Returns:
- the rule, to finish
-
otherwise
The color when no rule is true (OFF if you never say). Written anywhere: it is always last.- Parameters:
color- e.g.LightColor.BLUE- Returns:
- this module
-
allianceAtInit
The alliance at INIT on or off (on by default; see the class comment).allianceAtInitin this light's Tunables section is read at INIT: a call in Controls.java (made after that) wins over it; a call in Robot.java's define() (made before) does not.- Parameters:
on- false = the light shows your rules in INIT too, and no alliance flashes
-
allianceColors
The colors for the alliance at INIT, if your light shows red or blue badly.- Parameters:
blue- e.g.LightColor.BLUEred- e.g.LightColor.RED
-
blinkinPattern
public Lights blinkinPattern(LightColor color, com.qualcomm.hardware.rev.RevBlinkinLedDriver.BlinkinPattern pattern) A REV Blinkin only: show this pattern for this color (e.g. a strip whose plain blue is too dark:blinkinPattern(LightColor.BLUE, BlinkinPattern.BLUE_VIOLET)). Other lights ignore it.- Parameters:
color- the LightColor your rules usepattern- the Blinkin pattern to show for it (its names are on REV's Blinkin page)
-
showsAllianceAtInit
public boolean showsAllianceAtInit()True while the light shows the alliance in INIT (not turned off). -
clearRules
public void clearRules()Takes away every rule (the "otherwise" color stays). -
flash
Flashes a color now for half a second, over every rule: from a button (g2.a.press(() -> robot.lights.flash(LightColor.WHITE))) or at the end of an action (.then(() -> r.lights.flash(LightColor.GREEN))). A new flash replaces one still showing.- Parameters:
color- e.g.LightColor.WHITE
-
flash
Flashes a color now for this long, over every rule.- Parameters:
color- e.g.LightColor.WHITEseconds- how long, more than 0 (e.g. 0.5)
-
isFlashing
public boolean isFlashing()True while a flash is showing. -
color
The color the rules pick now (a blinking color counts even in its dark half). What the light really shows this instant isshowing(). -
showing
What the light shows right now: OFF in a blink's dark half. Updated every loop. -
update
public void update()Description copied from interface:SubsystemCalled once every loop. Do the hardware work here. Must be quick: no sleep, no waiting. While update() waits, the whole robot is frozen (no driving, no limits, no STOP). -
stop
public void stop()Description copied from interface:SubsystemStops all motion. Called at the end of every OpMode. -
addTelemetry
Description copied from class:ModuleThe part's telemetry line; each module adds its own.- Specified by:
addTelemetryin interfaceSubsystem- Overrides:
addTelemetryin classModule<Lights>
-