|
WS2812 RMT Driver
API 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 |
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.
|
explicit |
Construct a strip object.
| gpio | Output pin connected to the LEDs. |
| channel | RMT channel for signal generation. |
| 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().
|
static |
Generate a colour from a 0-255 position on a colour wheel.
| pos | Position on the colour wheel. |
|
inlinestaticconstexprnoexcept |
Get the compiled driver version string.
|
inlinestaticconstexprnoexcept |
Get the compiled driver major version number.
|
inlinestaticconstexprnoexcept |
Get the compiled driver minor version number.
|
inlinestaticconstexprnoexcept |
Get the compiled driver patch version number.
| uint32_t WS2812Strip::Length | ( | ) | const |
Get the number of LEDs managed by this strip.
| void WS2812Strip::SetBrightness | ( | uint8_t | value | ) |
Set global brightness for the strip.
| value | Brightness 0-255. |
| 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.
| num_leds | New number of LEDs in the strip. |
| void WS2812Strip::SetPixel | ( | uint32_t | index, |
| uint32_t | rgbw | ||
| ) |
Set the colour of a single LED.
| index | Index of the LED starting from 0. |
| rgbw | Packed colour: 0xRRGGBB, or 0xWWRRGGBB on an RGBW strip. Show() sends it in the order the LED reads it (green, red, blue, then white). |
| 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.
| 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.
|
staticconstexpr |
Length of the reset (latch) pulse that ends every frame: at least 280 us (WS2812B-V5).