How does one use += to gradually brighten a pixel?

How does one use += to gradually brighten a pixel? I see a lot of functions to gradually dim a pixel, but I want to take a pixel, make it brighter, then make it dim to black, one operation at a time. Ideally, I’d use +=/-=/%=, but I don’t know exactly how to use those to make something brighter. Any help is appreciated.

Did you read this already? https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors

Actually, is it possible to use the scale functions with a negative value? To brighten instead of darken?

No, no negative values. But you can subtract a scaled part from the maximum which does what you intend to do.

Well, have a look here: https://github.com/FastLED/FastLED/blob/master/lib8tion.h

brighten8_video( x) == 255 - dim8_video( 255 - x)
brighten8_raw( x) == 255 - dim8_raw( 255 - x)
brighten8_lin( x) == 255 - dim8_lin( 255 - x)

Is that probably what you are looking or?

The thing is, when you apply += and -= to a crgb you change its color. You need to do it proportionally on the 3 color chanels in order to maintain the color and only change the brightness.

Thanks @Stefan_Petrick . It’s close, but not quite, and those only operate on a single pixel. My actual goal is the following.

Take any pixel in the array, say #4 and it is CRGB::Blue. I want to take that blue and brighten it to white full on. Like an explosion. Then, I’ll back down through blue to black. Once I hit black, I’ll pick a new color, and bring that up to my level brightness (pry about 150).

I’ve tried a bunch of different ways, but it always looks a bit funny. I suspect I want to use HSV for this, but I just don’t know how. Sorry, I do a lot of embedded programming, but no visual or color related work. This is somewhat new to me.

@Peter_Buelow , I think you’re on the right track: keep your primary colors in an HSV array defined like this:
CHSV pixelColors[NUM_LEDS];
and work with them there, doing exactly the manipulations you have in mind… Then do this to display them:
// bulk convert HSVs to RGBs
hsv2rgb_rainbow( pixelColors, leds, NUM_LEDS);
FastLED.show();

OK, so alternatively, if you want (or need) to work exclusively in RGB, here’s how I’d animated from an individual color to full white: just keep adding a little bit of white each time eg. (32,32,32), and just keep doing that until you’re at (255,255,255). The operator+= will take care of the saturating math for you along the way. To come back down is another problem, because once you’re at (255,255,255), it’s hard to tell what color you’re trying to get back down to. I mean: there’s no latent information there to tell you whether you’re trying to get back down to Blue, or Red, or Green, or whatever.

Now something you could do, is not saturate all the way to (255,255,255), but instead stop very near full white, but leave yourself some clue as to what color you’re trying to fade back down to. E.g., keep increasing the brightness until you get to something (250,250,255) – very slightly blue, which then gives you a clue for what you need to ramp down to now.

But this is all pretty complicated and relatively finicky and annoying. I’d start with the idea of a ‘master’ CHSV array, and just render it to RGB at the last moment before calling FastLED.show().

Hope these comments help; let us know what you try next, and how it goes!

If the HSV color space is enough, you could also work within there and only manipulate the saturation (shifting the color towards white) while not touching the actual color component itself.

CHSV would work. I just don’t understand it very well. I’m guessing in HSV, I want to set H to be my color, S is how bright it is, and V probably stays the same. Is that correct? If so, then it’s just a matter of doing what @Mark_Kriegsman stated above. I tried the getting to very nearly white, but it never looked very good. I think this is probably a better option.

In a HSV (Hue-Saturation-Value) space hue is the color as shown here https://github.com/FastLED/FastLED/wiki/FastLED-HSV-Colors#color-map-rainbow-vs-spectrum
Low saturation values shift the color towards white, 255 gives you a pure color, 0 means pure white.
Value sets the brightness of the color, 0 means black, 255 maximum brightness.

If plain white looks not as good as you expect it to be, it will help to use the color correction.

Sometime it can be helpful to just play with a color picker for a few minutes to get a feel for what saturation and brightness and hue each mean. This one isn’t bad:
http://www.colorpicker.com

But for the effect described: hold hue and brightness constant. Start value (aka brightness) at 255, and go down to 0, then back up.

Awesome, thanks. I hate that I have to work for a living, although I can open my laptop at lunch. I won’t know what the next iteration looks like until late this evening. Unless the Bears are winning or it’s a good game, in which case I have to watch that instead.

One more question. If want an HSV value to fade close to white instead of just really bright H, I can set H, and then move V to 255 and S to 0, correct? Or is that backwards? I’d just try it, but can’t until pry tomorrow, so I was hoping to jumpstart it so I can just implement it right the first time.

Think of H as “what color of the rainbow” – keep that constant in this case. (Eg Blue.)

Think of S as “how RICH is the color (as opposed to pale and pastel)”. S=255 is the richest color: pure undiluted Blue. As S goes down, the color becomes lighter (more white-ish) turning first to light blue, then pastel blue, then blueish-white, until finally at S=0, you have just pure white – no more “blue” really at all.

Finally, think of V (aka Brightness) as just a plain old volume control on the LEDs. It doesn’t affect the ratio of R, G, and B – it just makes the whole color dimmer. You can take a pastel blue and turn down the V, and all you get is the same balance of RGB components, just less power going to the LEDs.

This is one of those times when (sadly, or happily), there’s no good substitute for playing around a bit. Can’t wait to see what you come up with!

Great explanation, thanks. That explanation makes it for me. I’ve got some code worked up which seems not complicated enough, but should work, and I hope to try it out later tonight. The help has been outstanding.