Skip to content
Michael Miller edited this page Mar 20, 2023 · 3 revisions

Other libraries have a method to dim all the pixels with one call. Is there a way to do this?

NOTE: NeoPixelBrightnessBus is being replaced by NeoPixelBusLg, which incorporates both brightness and gamma correction in a supportable model. This FAQ will get updated when the switch over has happened.

To get "brightness" support; you need to use the NeoPixelBrightnessBus object instead of NeoPixelBus object.
Due to the overhead of code and ram to support an overall brightness; a new object is used for those willing to sacrifice sketch size and ram for this support.

CAUTION: Dimming and then followed by brightening may cause loss of the original color nuances. This is due to quantization of the values when they are dimmed. This is no different than other libraries support.

But, if what you really want is to animate without the loss of color definition; then best way to do that is to remember the original color, calculate the target "dimmed" color, start an animation, and lerp (linear interpolate) between the original and target in the animation update callback.
The tricky part this solves is that you may want to apply gamma correction to the color values. Applying gamma to an iterative approach of read the last color, dim it a little, and set it back does not work correctly especially when applied across the complete strip with varying brightness already present. But Lerp-ing between two gamma corrected values or applying gamma correction after a lerp does work. So its important to remember the original and then lerp between it and the target on every iteration.

Clone this wiki locally