Class AddressableLED

java.lang.Object
edu.wpi.first.wpilibj.AddressableLED
All Implemented Interfaces:
AutoCloseable

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

Some LEDs use a different color order than the default GRB. The color order is configurable using setColorOrder(ColorOrder).

Up to 1024 LEDs may be controlled in total across all AddressableLED instances. A single global buffer is used for all instances. The start position used for LED data for the output is set via SetStart() and the length of the strip is set via SetLength(). Both of these default to zero, so multiple instances will access the same pixel data unless SetStart() is called to adjust the starting point.

  • Constructor Details

    • AddressableLED

      public AddressableLED(int channel)
      Constructs a new driver for a specific channel.
      Parameters:
      channel - the output channel to use
  • Method Details

    • close

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

      public int getChannel()
      Gets the output channel.
      Returns:
      the output channel
    • setColorOrder

      Sets the color order for this AddressableLED. The default order is GRB.

      This will take effect on the next call to setData(AddressableLEDBuffer).

      Parameters:
      order - the color order
    • setStart

      public void setStart(int start)
      Sets the display start of the LED strip in the global buffer.
      Parameters:
      start - the strip start, in LEDs
    • getStart

      public int getStart()
      Gets the display start of the LED strip in the global buffer.
      Returns:
      the strip start, in LEDs
    • setLength

      public void setLength(int length)
      Sets the length of the LED strip.
      Parameters:
      length - the strip length, in LEDs
    • setData

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

      This will write to the global buffer starting at the location set by setStart() and up to the length set by setLength().

      Parameters:
      buffer - the buffer to write
    • setGlobalData

      public static void setGlobalData(int start, AddressableLED.ColorOrder colorOrder, AddressableLEDBuffer buffer)
      Sets the LED output data at an arbitrary location in the global buffer.
      Parameters:
      start - the start location, in LEDs
      colorOrder - the color order
      buffer - the buffer to write