Class AddressableLED

All Implemented Interfaces:

public class AddressableLED
extends Object
implements AutoCloseable
A class for driving addressable LEDs, such as WS2812Bs and NeoPixels.

By default, the timing supports WS2812B LEDs, but is configurable using setBitTiming()

Only 1 LED driver is currently supported by the roboRIO.

  • Constructor Details

    • AddressableLED

      public AddressableLED​(int port)
      Constructs a new driver for a specific port.
      port - the output port to use (Must be a PWM header, not on MXP)
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • setLength

      public void setLength​(int length)
      Sets the length of the LED strip.

      Calling this is an expensive call, so it's best to call it once, then just update data.

      The max length is 5460 LEDs.

      length - the strip length
    • setData

      public void setData​(AddressableLEDBuffer buffer)
      Sets the LED output data.

      If the output is enabled, this will start writing the next data cycle. It is safe to call, even while output is enabled.

      buffer - the buffer to write
    • setBitTiming

      public void setBitTiming​(int highTime0NanoSeconds, int lowTime0NanoSeconds, int highTime1NanoSeconds, int lowTime1NanoSeconds)
      Sets the bit timing.

      By default, the driver is set up to drive WS2812Bs, so nothing needs to be set for those.

      highTime0NanoSeconds - high time for 0 bit (default 400ns)
      lowTime0NanoSeconds - low time for 0 bit (default 900ns)
      highTime1NanoSeconds - high time for 1 bit (default 900ns)
      lowTime1NanoSeconds - low time for 1 bit (default 600ns)
    • setSyncTime

      public void setSyncTime​(int syncTimeMicroSeconds)
      Sets the sync time.

      The sync time is the time to hold output so LEDs enable. Default set for WS2812B.

      syncTimeMicroSeconds - the sync time (default 280us)
    • start

      public void start()
      Starts the output.

      The output writes continuously.

    • stop

      public void stop()
      Stops the output.