WS2812 RMT Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
WS2812Strip Class Reference

C++ convenience wrapper for a chain of WS2812 LEDs. More...

#include <ws2812_cpp.hpp>

Public Member Functions

 WS2812Strip (gpio_num_t gpio=(gpio_num_t) CONFIG_WS2812_LED_RMT_TX_GPIO, int channel=CONFIG_WS2812_LED_RMT_TX_CHANNEL, uint32_t num_leds=NUM_LEDS, LedType type=LedType::RGB, uint16_t t0h=WS2812_T0H, uint16_t t1h=WS2812_T1H, uint16_t t0l=WS2812_T0L, uint16_t t1l=WS2812_T1L, uint8_t brightness=WS2812_DEFAULT_BRIGHTNESS)
 Construct a strip object.
 
esp_err_t Begin ()
 Report whether the strip's RMT channel is ready, retrying its set-up if it failed.
 
void SetPixel (uint32_t index, uint32_t rgbw)
 Set the colour of a single LED.
 
uint32_t Length () const
 
esp_err_t Show ()
 Send the currently stored colours to the LED strip.
 
void SetBrightness (uint8_t value)
 Set global brightness for the strip.
 
void SetNumLeds (uint32_t num_leds)
 Resize the strip to a new LED count at runtime.
 
void SetTimings (uint16_t t0h, uint16_t t1h, uint16_t t0l, uint16_t t1l)
 Update the bit timing parameters.
 

Static Public Member Functions

static uint32_t ColorWheel (uint8_t pos)
 Generate a colour from a 0-255 position on a colour wheel.
 
static constexpr const char * GetDriverVersion () noexcept
 Get the compiled driver version string.
 
static constexpr uint8_t GetDriverVersionMajor () noexcept
 Get the compiled driver major version number.
 
static constexpr uint8_t GetDriverVersionMinor () noexcept
 Get the compiled driver minor version number.
 
static constexpr uint8_t GetDriverVersionPatch () noexcept
 Get the compiled driver patch version number.
 

Static Public Attributes

static constexpr uint32_t kResetTimeUs = 300
 

Detailed Description

C++ convenience wrapper for a chain of WS2812 LEDs.

All configuration such as GPIO, channel, LED type and timing can be supplied at runtime via the constructor, allowing multiple strips with different settings.

Constructor & Destructor Documentation

◆ WS2812Strip()

WS2812Strip::WS2812Strip ( gpio_num_t  gpio = (gpio_num_t)CONFIG_WS2812_LED_RMT_TX_GPIO,
int  channel = CONFIG_WS2812_LED_RMT_TX_CHANNEL,
uint32_t  num_leds = NUM_LEDS,
LedType  type = LedType::RGB,
uint16_t  t0h = WS2812_T0H,
uint16_t  t1h = WS2812_T1H,
uint16_t  t0l = WS2812_T0L,
uint16_t  t1l = WS2812_T1L,
uint8_t  brightness = WS2812_DEFAULT_BRIGHTNESS 
)
explicit

Construct a strip object.

Parameters
gpioOutput pin connected to the LEDs.
channelRMT channel for signal generation.

Member Function Documentation

◆ Begin()

esp_err_t WS2812Strip::Begin ( )

Report whether the strip's RMT channel is ready, retrying its set-up if it failed.

The constructor already creates the channel; it no longer aborts when that fails. Call Begin() and check the result before the first Show().

Returns
ESP_OK when the channel is ready, otherwise the ESP-IDF error (for example ESP_ERR_NOT_FOUND when no RMT transmit channel is free).

◆ ColorWheel()

uint32_t WS2812Strip::ColorWheel ( uint8_t  pos)
static

Generate a colour from a 0-255 position on a colour wheel.

Parameters
posPosition on the colour wheel.
Returns
Packed RGB colour.

◆ GetDriverVersion()

static constexpr const char * WS2812Strip::GetDriverVersion ( )
inlinestaticconstexprnoexcept

Get the compiled driver version string.

◆ GetDriverVersionMajor()

static constexpr uint8_t WS2812Strip::GetDriverVersionMajor ( )
inlinestaticconstexprnoexcept

Get the compiled driver major version number.

◆ GetDriverVersionMinor()

static constexpr uint8_t WS2812Strip::GetDriverVersionMinor ( )
inlinestaticconstexprnoexcept

Get the compiled driver minor version number.

◆ GetDriverVersionPatch()

static constexpr uint8_t WS2812Strip::GetDriverVersionPatch ( )
inlinestaticconstexprnoexcept

Get the compiled driver patch version number.

◆ Length()

uint32_t WS2812Strip::Length ( ) const

Get the number of LEDs managed by this strip.

◆ SetBrightness()

void WS2812Strip::SetBrightness ( uint8_t  value)

Set global brightness for the strip.

Parameters
valueBrightness 0-255.

◆ SetNumLeds()

void WS2812Strip::SetNumLeds ( uint32_t  num_leds)

Resize the strip to a new LED count at runtime.

Clears all pixel data to zero. The RMT symbol buffer is resized to match the new LED count and current colour encoding.

Parameters
num_ledsNew number of LEDs in the strip.

◆ SetPixel()

void WS2812Strip::SetPixel ( uint32_t  index,
uint32_t  rgbw 
)

Set the colour of a single LED.

Parameters
indexIndex of the LED starting from 0.
rgbwPacked colour: 0xRRGGBB, or 0xWWRRGGBB on an RGBW strip. Show() sends it in the order the LED reads it (green, red, blue, then white).

◆ SetTimings()

void WS2812Strip::SetTimings ( uint16_t  t0h,
uint16_t  t1h,
uint16_t  t0l,
uint16_t  t1l 
)

Update the bit timing parameters.

Allows adjustment of the WS2812 protocol timings after construction.

◆ Show()

esp_err_t WS2812Strip::Show ( )

Send the currently stored colours to the LED strip.

Sends every pixel green, red, blue (then white), followed by a reset (line low for kResetTimeUs) that latches the frame. Blocks until the frame is on the wire.

Member Data Documentation

◆ kResetTimeUs

constexpr uint32_t WS2812Strip::kResetTimeUs = 300
staticconstexpr

Length of the reset (latch) pulse that ends every frame: at least 280 us (WS2812B-V5).


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