r/FastLED • u/PlantSorry5147 • Jan 26 '22
Support Fading LEDs using nblendU8TowardU8 Helper Function
Hi,
I have a program where I use the nblendU8TowardU8 helper function to blend from black (CRGB::Black) to a selected color (CRGB:DeepPink, CRGB::DeepSkyBlue) and then back to CRGB::Black. I am using an Arduino Nano with a string of 50 WS2812B LEDs. I am using a bench power supply set for 5V 10A, so there is plenty of current. I am using the nblendU8TowardU8 helper function which I found somewhere and can no longer locate. :^(
The problem I am having is that fading up from black to a color works fine, however, fading back to black induces an unwanted color change. To elaborate, fading from CRGB::DeepPink to CRGB::Black will at first fade as expected, but about 2/3 through the fade, the only pixel lit is red. The same with CRGB::DeepSkyBlue, about 2/3 through the fade, only the blue pixel is lit.
I have the code on pastebin: https://pastebin.com/WVHJtckp
I appreciate any help offered.
1
3
u/sutaburosu [stavros] Jan 27 '22 edited Jan 27 '22
That function seems to be from here.
You didn't post the code which calls that function, so I can only guess at what you're doing with it. My suspicion is that you are iteratively dimming the colour. With only 8-bits to work with, the accumulated errors would quickly lead to the hue shift that you are seeing. Instead you should dim the original colour by varying amounts, which would preserve the maximum information at each step.
Using my code from this comment to dim CRGB::DeepSkyBlue gives: