Class Lights

java.lang.Object
com.crossbotics.ftchelper.robot.Module<Lights>
com.crossbotics.ftchelper.robot.Lights
All Implemented Interfaces:
Subsystem

public final class Lights extends Module<Lights>
A colored light the drivers can see: green when the launcher is ready to fire, orange blinking when it is jammed, a white flash when a shot goes, yellow in the last 20 seconds. You write rules; every loop the light shows the first rule that is true.

 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
 

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
    Modifier and Type
    Class
    Description
    final class 
    One rule, started with show(LightColor).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    How long the alliance color flashes at START and when the alliance is switched, seconds.
    static final double
    Blinks per second when none is given.
    static final double
    Blinks per second of "choose the alliance" in INIT (slow: well under the 5 per second limit).
    static final double
    A flash's length when none is given: half a second.
    static final double
    The most blinks per second allowed (FTC R202 J: faster than 5 per second invites the referees).
    static final double
    The 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 Type
    Method
    Description
    void
    The 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).
    The colors for the alliance at INIT, if your light shows red or blue badly.
    static Lights
    A 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.
    void
    Takes away every rule (the "otherwise" color stays).
    The color the rules pick now (a blinking color counts even in its dark half).
    void
    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))).
    void
    flash(LightColor color, double seconds)
    Flashes a color now for this long, over every rule.
    static Lights
    gobilda(String servoName)
    A goBILDA RGB Indicator Light (3118-0808-0002), plugged into a servo port.
    boolean
    True while a flash is showing.
    The color when no rule is true (OFF if you never say).
    Starts a rule: the color to show.
    What the light shows right now: OFF in a blink's dark half.
    boolean
    True while the light shows the alliance in INIT (not turned off).
    void
    Stops all motion.
    void
    Called once every loop.

    Methods inherited from class com.crossbotics.ftchelper.robot.Module

    deviceName, isOptional, isPresent, looks, name, optional, part, tunables, zone, zoneAbove, zoneBelow

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FLASH_SEC

      public static final double FLASH_SEC
      A flash's length when none is given: half a second.
      See Also:
    • MIN_CHANGE_SEC

      public static final double MIN_CHANGE_SEC
      The 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_SEC
      How long the alliance color flashes at START and when the alliance is switched, seconds.
      See Also:
    • CHOOSE_HZ

      public static final double CHOOSE_HZ
      Blinks per second of "choose the alliance" in INIT (slow: well under the 5 per second limit).
      See Also:
  • Method Details

    • gobilda

      public static Lights gobilda(String servoName)
      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

      public static Lights blinkin(String name)
      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

      public Lights.Rule show(LightColor color)
      Parameters:
      color - e.g. LightColor.GREEN
      Returns:
      the rule, to finish
    • otherwise

      public Lights otherwise(LightColor color)
      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

      public Lights allianceAtInit(boolean on)
      The alliance at INIT on or off (on by default; see the class comment). allianceAtInit in 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

      public Lights allianceColors(LightColor blue, LightColor red)
      The colors for the alliance at INIT, if your light shows red or blue badly.
      Parameters:
      blue - e.g. LightColor.BLUE
      red - 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 use
      pattern - 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

      public void flash(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))). A new flash replaces one still showing.
      Parameters:
      color - e.g. LightColor.WHITE
    • flash

      public void flash(LightColor color, double seconds)
      Flashes a color now for this long, over every rule.
      Parameters:
      color - e.g. LightColor.WHITE
      seconds - how long, more than 0 (e.g. 0.5)
    • isFlashing

      public boolean isFlashing()
      True while a flash is showing.
    • color

      public LightColor color()
      The color the rules pick now (a blinking color counts even in its dark half). What the light really shows this instant is showing().
    • showing

      public LightColor 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: Subsystem
      Called 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: Subsystem
      Stops all motion. Called at the end of every OpMode.
    • addTelemetry

      public void addTelemetry(RobotTelemetry t)
      Description copied from class: Module
      The part's telemetry line; each module adds its own.
      Specified by:
      addTelemetry in interface Subsystem
      Overrides:
      addTelemetry in class Module<Lights>