Hi I’m working on a project where each LED in the strip has a

Hi I’m working on a project where each LED in the strip has a fixed (but different) color and the brightness of every LED is changed to a new (individual) value every time through the loop. It seems that working in the HSV color space is the best way to do this. The Hue and Saturation levels are fixed while the Value parameter is changed every time through the loop.

But, I’m pretty sure that only a CRGB array can be passed to the “addLeds()” method. So, I maintain a separate “shadow” CHSV array of the same size. Every time through the loop I change the Level parameter of each element in the CHSV array and then copy it to the corresponding element of my CRGB “leds” array. When I’m done, I call the “show()” method.

Is this the best way to do it? The brightness needs to be an absolute value, not relative. So, I don’t think I can use color math or the “fadeLightBy()” / “nscale8()” methods.

Thanks all.

Conversion from CHSV to CRGB is handled automatically by FastLED. So, define your CRGB array normally, then just assign leds[x] = CHSV(hue, sat, value); like in the examples: https://github.com/FastLED/FastLED/blob/master/examples/Cylon/Cylon.ino#L44

I understand that. But in order change the value (brightness) with “led[i] = CHSV(hue, sat, value)” I have to also KNOW what hue and sat are. As I said, they are different (but fixed) for every LED in the string. There is no “led[i].changeValue” method, and the “led[i]” array elements are CRGB objects, so they can’t tell me their hue or sat values. So, if I only want to change the value (brightness) setting, I have to store the corresponding hue and sat values SOMEWHERE. That’s why I use a CHSV array of the same size to “shadow” the “led[]” array. So, every time through the loop I do “shadowArray[i].value = newBrightness” and then “led[i] = shadowArray[i]”.

Is there a better way?

Ah, sorry, read your question too quickly… :slight_smile:

There’s the rgb2hsv_approximate function (with several caveats): https://github.com/FastLED/FastLED/blob/03d12093a92ee2b64fabb03412aa0c3e4f6384dd/hsv2rgb.h#L52

I’d go with your idea of a shadow array, the rgb2hsv builds errors of your keep going back and forth.

@Greg_Valvo ​​ The only drawback I see is the extra memory needed for the intermediary HSV array (and probably only an issue if you have a large number is pixels). I think the way you are doing it is fine.

An alternative would be to have a look at these to see if they might be any use in your case:
https://github.com/FastLED/FastLED/blob/master/hsv2rgb.h

OK, thanks. I’m sticking with what I have. I’ll gladly take the small memory hit in exchange for the higher performance gained by not using “rgb2hsv_approximate”