Package edu.wpi.first.wpilibj
Class AddressableLED
java.lang.Object
edu.wpi.first.wpilibj.AddressableLED
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Order that color data is sent over the wire. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
int
Gets the output channel.int
getStart()
Gets the display start of the LED strip in the global buffer.void
Sets the color order for this AddressableLED.void
setData
(AddressableLEDBuffer buffer) Sets the LED output data.static void
setGlobalData
(int start, AddressableLED.ColorOrder colorOrder, AddressableLEDBuffer buffer) Sets the LED output data at an arbitrary location in the global buffer.void
setLength
(int length) Sets the length of the LED strip.void
setStart
(int start) Sets the display start of the LED strip in the global buffer.
-
Constructor Details
-
AddressableLED
Constructs a new driver for a specific channel.- Parameters:
channel
- the output channel to use
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
-
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
Sets the display start of the LED strip in the global buffer.- Parameters:
start
- the strip start, in LEDs
-
getStart
Gets the display start of the LED strip in the global buffer.- Returns:
- the strip start, in LEDs
-
setLength
Sets the length of the LED strip.- Parameters:
length
- the strip length, in LEDs
-
setData
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 LEDscolorOrder
- the color orderbuffer
- the buffer to write
-