WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
frc::AddressableLED Class Reference

A class for driving addressable LEDs, such as WS2812B, WS2815, and NeoPixels. More...

#include <frc/AddressableLED.h>

Classes

class  LEDData
 

Public Types

enum  ColorOrder {
  kRGB = HAL_ALED_RGB , kRBG = HAL_ALED_RBG , kBGR = HAL_ALED_BGR , kBRG = HAL_ALED_BRG ,
  kGBR = HAL_ALED_GBR , kGRB = HAL_ALED_GRB
}
 Order that color data is sent over the wire. More...
 

Public Member Functions

 AddressableLED (int channel)
 Constructs a new driver for a specific channel.
 
 AddressableLED (AddressableLED &&)=default
 
AddressableLEDoperator= (AddressableLED &&)=default
 
int GetChannel () const
 Gets the channel for this addressable LED.
 
void SetColorOrder (ColorOrder order)
 Sets the color order for this AddressableLED.
 
void SetStart (int start)
 Sets the display start of the LED strip in the global buffer.
 
int GetStart () const
 Gets the display start of the LED strip in the global buffer.
 
void SetLength (int length)
 Sets the length of the LED strip.
 
void SetData (std::span< const LEDData > ledData)
 Sets the LED output data.
 
void SetData (std::initializer_list< LEDData > ledData)
 Sets the LED output data.
 

Static Public Member Functions

static void SetGlobalData (int start, ColorOrder colorOrder, std::span< const LEDData > ledData)
 Sets the LED output data at an arbitrary location in the global buffer.
 

Detailed Description

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().

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.

Member Enumeration Documentation

◆ ColorOrder

Order that color data is sent over the wire.

Enumerator
kRGB 

RGB order.

kRBG 

RBG order.

kBGR 

BGR order.

kBRG 

BRG order.

kGBR 

GBR order.

kGRB 

GRB order. This is the default order.

Constructor & Destructor Documentation

◆ AddressableLED() [1/2]

frc::AddressableLED::AddressableLED ( int channel)
explicit

Constructs a new driver for a specific channel.

Parameters
channelthe output channel to use

◆ AddressableLED() [2/2]

frc::AddressableLED::AddressableLED ( AddressableLED && )
default

Member Function Documentation

◆ GetChannel()

int frc::AddressableLED::GetChannel ( ) const
inline

Gets the channel for this addressable LED.

Returns
channel

◆ GetStart()

int frc::AddressableLED::GetStart ( ) const
inline

Gets the display start of the LED strip in the global buffer.

Returns
the strip start, in LEDs

◆ operator=()

AddressableLED & frc::AddressableLED::operator= ( AddressableLED && )
default

◆ SetColorOrder()

void frc::AddressableLED::SetColorOrder ( ColorOrder order)

Sets the color order for this AddressableLED.

The default order is GRB.

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

Parameters
orderthe color order

◆ SetData() [1/2]

void frc::AddressableLED::SetData ( std::initializer_list< LEDData > ledData)

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
ledDatathe buffer to write

◆ SetData() [2/2]

void frc::AddressableLED::SetData ( std::span< const LEDData > ledData)

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
ledDatathe buffer to write

◆ SetGlobalData()

static void frc::AddressableLED::SetGlobalData ( int start,
ColorOrder colorOrder,
std::span< const LEDData > ledData )
static

Sets the LED output data at an arbitrary location in the global buffer.

Parameters
startthe start location, in LEDs
colorOrderthe color order
ledDatathe buffer to write

◆ SetLength()

void frc::AddressableLED::SetLength ( int length)

Sets the length of the LED strip.

Parameters
lengththe strip length, in LEDs

◆ SetStart()

void frc::AddressableLED::SetStart ( int start)

Sets the display start of the LED strip in the global buffer.

Parameters
startthe strip start, in LEDs

The documentation for this class was generated from the following file: