mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-09 22:04:27 +02:00
Updated FAQ #9 (markdown)
11
FAQ-#9.md
11
FAQ-#9.md
@@ -1,11 +1,10 @@
|
||||
### Other libraries have a method to dim all the pixels with one call. Is there a way to do this?
|
||||
There is not a method that will "darken all" in one call.
|
||||
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.
|
||||
|
||||
It can be simply implemented by iterating over all pixels, get the pixel color, call `Darken()` on it, and then set the pixel with the new color.
|
||||
|
||||
But, what you really want is to animate it dimming and not just "blink" to the dimmed color. The best way to do that is to remember the original color, calculate the target "dimmed" color, start an animation, and lerp between the original and target in the animation update callback. The tricky part 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. 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 lerp between it and the target on every iteration.
|
||||
|
||||
The NeoPixelBus can not manage animations, this is the job of your sketch. So exposing the "darken all" method would confuse how to best do this work; so it was specifically left out of the API.
|
||||
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.
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user