ESPectro32 Library
Library for using ESPectro32 board
|
Driver for WS2812/NeoPixel data. More...
#include <WS2812.h>
Public Member Functions | |
WS2812 (gpio_num_t gpioNum, uint16_t pixelCount, int channel=RMT_CHANNEL_0) | |
Construct a wrapper for the pixels. More... | |
void | show () |
Show the current Neopixel data. More... | |
void | setColorOrder (char *order) |
Set the color order of data sent to the LEDs. More... | |
void | setPixel (uint16_t index, uint8_t red, uint8_t green, uint8_t blue) |
Set the given pixel to the specified color. More... | |
void | setPixel (uint16_t index, RgbLedColor_t pixel) |
Set the given pixel to the specified color. More... | |
void | setPixel (uint16_t index, uint32_t pixel) |
Set the given pixel to the specified color. More... | |
void | setBrightness (uint16_t index, uint8_t factor) |
void | setBrightnessPercent (uint16_t index, float percent) |
void | clear () |
Clear all the pixel colors. More... | |
uint16_t | getPixelCount () |
virtual | ~WS2812 () |
Class instance destructor. | |
Private Attributes | |
char * | colorOrder |
uint16_t | pixelCount |
rmt_channel_t | channel |
rmt_item32_t * | items |
RgbLedColor_t * | pixels |
uint8_t * | brightnesses = NULL |
Driver for WS2812/NeoPixel data.
NeoPixels or WS2812s are LED devices that can illuminate in arbitrary colors with 8 bits of data for each of the red, green and blue channels. These devices can be daisy chained together to produce a string of LEDs. If we call each LED instance a pixel, then when we want to set the value of a string of pixels, we need to supply the data for all the pixels. This class encapsulates setting the color value for an individual pixel within the string and, once you have set up all the desired colors, you can then set all the pixels in a show() operation. The class hides from you the underlying details needed to drive the devices.
WS2812::WS2812 | ( | gpio_num_t | dinPin, |
uint16_t | pixelCount, | ||
int | channel = RMT_CHANNEL_0 |
||
) |
Construct a wrapper for the pixels.
In order to drive the NeoPixels we need to supply some basic information. This includes the GPIO pin that is connected to the data-in (DIN) of the devices. Since we also want to be able to drive a string of pixels, we need to tell the class how many pixels are present in the string.
[in] | gpioNum | The GPIO pin used to drive the data. |
[in] | pixelCount | The number of pixels in the strand. |
[in] | channel | The RMT channel to use. Defaults to RMT_CHANNEL_0. |
void WS2812::clear | ( | void | ) |
Clear all the pixel colors.
This sets all the pixels to off which is no brightness for all of the color channels. The LEDs are not actually updated until a call to show().
void WS2812::setColorOrder | ( | char * | colorOrder | ) |
Set the color order of data sent to the LEDs.
Data is sent to the WS2812s in a serial fashion. There are 8 bits of data for each of the three channel colors (red, green and blue). The WS2812 LEDs typically expect the data to arrive in the order of "green" then "red" then "blue". However, this has been found to vary between some models and manufacturers. What this means is that some want "red", "green", "blue" and still others have their own orders. This function can be called to override the default ordering of "GRB". We can specify an alternate order by supply an alternate three character string made up of 'R', 'G' and 'B' for example "RGB".
void WS2812::setPixel | ( | uint16_t | index, |
uint8_t | red, | ||
uint8_t | green, | ||
uint8_t | blue | ||
) |
Set the given pixel to the specified color.
The LEDs are not actually updated until a call to show().
[in] | index | The pixel that is to have its color set. |
[in] | red | The amount of red in the pixel. |
[in] | green | The amount of green in the pixel. |
[in] | blue | The amount of blue in the pixel. |
void WS2812::setPixel | ( | uint16_t | index, |
RgbLedColor_t | pixel | ||
) |
Set the given pixel to the specified color.
The LEDs are not actually updated until a call to show().
[in] | index | The pixel that is to have its color set. |
[in] | pixel | The color value of the pixel. |
void WS2812::setPixel | ( | uint16_t | index, |
uint32_t | pixel | ||
) |
Set the given pixel to the specified color.
The LEDs are not actually updated until a call to show().
[in] | index | The pixel that is to have its color set. |
[in] | pixel | The color value of the pixel. |
void WS2812::show | ( | ) |
Show the current Neopixel data.
Drive the LEDs with the values that were previously set.