Skip to content

NeoPixelBusLg object API

Michael Miller edited this page Apr 6, 2023 · 2 revisions

NOTE: In most ways this will act like the NeoPixelBus object, except it will apply luminance modification and gamma correction. key differences will be called out below but otherwise refer to the NeoPixelBus Api.

Construction and Template Arguments

The constructor will require the declaration of several template arguments that specialize the class to the sketch writer's needs. These class types are provided for the author and there is no need to implement them.

NeoPixelBusLg<T_COLOR_FEATURE, T_METHOD, T_GAMMA>(...)

T_COLOR_FEATURE - the specialization class for the color feature.
T_METHOD - the specialization class for the method.
T_GAMMA - (optional) the specialization class for the gamma correction. If not provided it will default to NeoGammaEquationMethod.

NeoPixelBusLg<T_COLOR_FEATURE, T_METHOD, T_GAMMA>(uint16_t countPixels, uint8_t pin)

This will define the object with the given Feature, Method, and Gamma; and construct it to handle the countPixels on the given pin.

  • countPixels - The number of pixels on the physical bus. This is limited primarily by memory to contain a buffer for them.
  • pin - The output pin to use. Note that some platforms and Methods restrict the Pin and thus this constructor should not be used on them. On Esp8266 use the constructor that omits the pin.

NeoPixelBusLg<T_COLOR_FEATURE, T_METHOD, T_GAMMA>(uint16_t countPixels)

This will define the object with the given Feature, Method, and Gamma; and construct it to handle the countPixels using a hardware defined pin.
For Esp8266 this is the constructor to use.
For DotStar using SPI this is the constructor to use.

  • countPixels - The number of pixels on the physical bus. This is limited primarily by memory to contain a buffer for them. Some Methods (ex. NeoEsp8266Dma800KbpsMethod) require more buffer than others and you should refer to their documentation.

NeoPixelBusLg<T_COLOR_FEATURE, T_METHOD, T_GAMMA>(uint16_t countPixels, uint8_t pinClock, uint8_t pinData)

This will define the object with the given Feature, Method, and Gamma; and construct it to handle the countPixels on the given clock and data pins. This is used with DotStars only.

  • countPixels - The number of pixels on the physical bus. This is limited primarily by memory to contain a buffer for them.
  • pinClock - The clock output pin to use.
  • pinData - The data output pin to use.

Methods

Please refer to the NeoPixelBus API Methods as they are compatible objects. Key uniqueness is listed below.

void SetLuminance(uint8_t luminance)

This will set the luminance level for all new values being set. Changing this does not affect all previous pixel values.

  • luminance - (0-255) The luminance value to use, this will blend all new colors between black and their value, where 0 would be black and 255 would the color set. This is applied before gamma correction.

uint8_t GetLuminance() const

This will return the luminance level currently being used.

uint8_t* Pixels()

This will return a pointer to the internal buffer of pixels. See PixelsSize() and PixelSize() to understand how large this buffer is and how its laid out. If you modify the buffer contents, you will need to let the NeoPixelBus know this by calling the Dirty() method otherwise Show() will not update the pixels.
NOTE: This buffer represents the pixels after luminance and gamma correction is applied, modifying it means that it will not have luminance and gamma applied to it unless you call ApplyPostAdjustments().
CAUTION: The pointer returned should not be cached or retained between calls of Show(). The value may change after calling Show()

void SetPixelColor(uint16_t indexPixel, ColorObject color)

This will set the color for the given pixel. The color will be adjusted for luminance and gamma before being stored.

  • indexPixel - the pixel number
  • color - a color object to use, RgbColor, HslColor, and HsbColor will all work and if the NeoPixelBus object was created with the NeoRgbwFeature the RgbwColor will also work.

ColorObject GetPixelColor(uint16_t indexPixel)

This will return the color for the given pixel. The value returned is not the original color that was passed into the SetPixelColor() as that value was adjusted for luminance and gamma before being stored. And thus, the return will also be adjusted.

  • indexPixel - the pixel number
  • <return>, a adjusted and corrected color object, RgbColor or RgbwColor.

void ClearTo(ColorObject color)

This will clear all pixels to the given color. The color will be adjusted for luminance and gamma before being stored.

  • color - a color object to use, RgbColor, HslColor, and HsbColor will all work and if the NeoPixelBus object was created with the NeoRgbwFeature the RgbwColor will also work.

void ClearTo(ColorObject color, uint16_t first, uint16_t last)

This will clear all pixels from first to last to the given color. The color will be adjusted for luminance and gamma before being stored.

  • color - a color object to use, RgbColor, HslColor, and HsbColor will all work and if the NeoPixelBus object was created with the NeoRgbwFeature the RgbwColor will also work.
  • first - the index to the first pixel to start clearing
  • last - the index to the last pixel that will be cleared

void ApplyPostAdjustments()

This will apply luminance and gamma adjustments to all existing stored pixel data; even if previously applied by calling SetPixelColor(). It is primarily used when the Pixels() method is used to directly access and set all pixel data into the memory buffer that will then need to be corrected.

Shader object

The class exposes an instanced object Shader that is a type of LuminanceShader. This allows external NeoDib buffers to render into the NeoPixelBusLg using the luminance and gamma correction already defined and used in the strip.

typedef NeoPixelBusLg<NeoGrbFeature, NeoWs2812xMethod> MyBusType;
MyBusType strip(PixelCount, PixelPin);
NeoDib<RgbColor> image(PixelCount);

...

image.Render<NeoGrbFeature, MyBusType::LuminanceShader>(strip, strip.Shader);
Clone this wiki locally