With leds[i] = CHSV(HUE, SATURATION, BRIGHTNESS) how can I change only the BRIGHTNESS value,

With

leds[i] = CHSV(HUE, SATURATION, BRIGHTNESS)

how can I change only the BRIGHTNESS value, when operating on the leds array that is filled from a gradient palette?

In cases like these, HUE and SATURATION are unknown or, rather, generated programmatically. Is there a function to do this:

leds[i] = CHSV(as is, as is, BRIGHTNESS)

Thanks!

This should work:

leds[i] = ColorFromPalette (palette, index, brightness);

http://fastled.io/docs/3.1/group___colorutils.html

Thanks, so there would be no conflict using that method twice - once in a function that populates leds EVERY_N_SECONDS from a palette, and then in another function that does random brightness manipulation with it? There is no generic

leds[i].brighten(value);
leds[i].darken(value);

way of doing it, independent of palette usage?

So you can’t do it where the LEDs are set from the palette?

With CHSV, it’s easy to adjust value/brightness:

CHSV color = CHSV(h, s, v);
hsv.v -= 1;

But once you’ve assigned an LED (leds[i] = …), it’s converted to CRGB. So you’ll need an array of CHSV:

CRGB leds[NUM_LEDS];
CHSV colors[NUM_LEDS];

Then you can assign CHSV to colors without losing the HSV values, perform all the adjustment you want/need, then assign from colors to leds.

Forgot to mention: there’s no perfect way of adjusting brightness/value of CRGB without data loss, but there is a way: https://plus.google.com/112916219338292742137/posts/Rxx6RpgpSr2

@Andreas_Hopf
“…so there would be no conflict using that method twice - once in a function that populates leds EVERY_N_SECONDS from a palette, and then in another function…”

It’s fine to do something like that. You can (re)assign values to a pixel as much/often as you like. You must call FastLED.show() to send the new data to the strip and actually see the change though.

@Jason_Coon @marmil Thank you both! The thing is with

CHSV color = CHSV(h, s, v);

I need to specify h and s also, but I can’t know what they are.

The colours are set independently for all 144 LEDs by a function that EVERY_N_MINUTES fetches a new colour from a palette, which works very well on its own.

The other function EVERY_N_MILLISECONDS, similar to the @Mark_Kriegsman example, randomly darkens/brightens LEDs with a state flag, and that also works very well on its own.

In other words, the second function needs, apart from the random LED selection stuff, to simply manipulate just the v component of certain LEDs, if you see what I mean. So in the end I have in the loop

ultraslowPalette(); - goes through a palette over an hour
fairlyFastTwinkle(); - darkens/brightens random LEDs quickly
doSomethingElse();
FastLED.show();

If I were to use

leds[i] = ColorFromPalette (palette, index, brightness);

also in the fairlyFastTwinkle() function, I would interfere with the other function that with a different timing already fetches colours from the palette.

Another idea how to manipulate brightness of individual LEDs - there are HSV setter methods like

leds[i].setHSV(224, 187, 255);
leds[i].setHue(224);

so could I, with some guidance, enhance the FastLED library with a

leds[i].setVal(#);

setter method? And, while at it, a

leds[i].setSat(#);

method, too? Then one would be easily able to manipulate each element of the leds array, no matter how the 144 LEDs of a strip have just been filled.

Yeah, except setVal and setSat only work on HSV, not RGB. You should be able to use rgb2hsv_approximate (mentioned above):

CHSV color = rgb2hsv_approximate(leds[i]);
color.v -= 1;
color.setVal(#);
color.setSat(#);
leds[i] = color;

@Jason_Coon Cheers, but “Yeah, except setVal and setSat only work on HSV, not RGB” - that would exactly be what I want, sounds just right. So I understand you saying these methods do exist? This approximate stuff seems quite cumbersome just to change V, compared to how simple changing the H leds[i].setHue(#); is.

Maybe I just have to live with

leds[i].addToRGB(#);
leds[i].subtractFromRGB(#);

to darken/brighten in the end.

Those methods exist, but only for CHSV, not CRGB. Your leds array is CRGB. The only way to get from CRGB to CHSV is rgb2hsv_approximate. Or you could just store the CHSV in a separate array, as noted above.

@Jason_Coon Ok, thanks. I think I understand now. Because

CRGBPalette16 activePalette = testPalette;
CRGB colour = ColorFromPalette();

one can only work with RGB methods, if one is no coding wizard with rgb2hsv_approximate and wants to keep it simple; so that means in my case, being no coding wizard, I best use

leds[i].addToRGB(#);
leds[i].subtractFromRGB(#);

to darken/brighten leds array elements that are constantly filled by extrapolation from a palette.

leds[i].addToRGB(#);
leds[i].subtractFromRGB(#);

did not work, while the gradient palette fills the strip; the colours change too much instead of just becoming darker or brighter.

Dimming and brightening of what’s already in the leds array is hellishly difficult ; )