One part which may confuse people is when you’re talking setting the RGB values of the LEDs.
leds[i][0] = 50; // red
leds[i][1] = 100; // green
leds[i][2] = 150; // blue
Some people may think that the different values are giving different colours for the leds. EG leds[i][0] = 50; // red makes it red… leds[i][1] = 100; // green makes it green etc.
Rather than it’s setting the values for the Red, Green and Blue channels
I prefer to user leds[i] = CRGB(r,g,b) for assigning colours, which might be more readable for newer users, where r,g,b are ints for red, green and blue respectively
And the majority of the time I’m actually using
leds[i] = CHSV(h,s,v) where h,s,v are ints for hue, saturation and value respectively
@Chaka_September good point. I actually just copied that from the FastLED wiki, as I was trying to bounce back and forth between their content and explanations. I can see how that doesn’t flow with just setting red. Didn’t catch that!
I don’t think it’s possible to set brightness via CRGB, other than CRGB(127,0,0) being half the brightness of CRGB(254,0,0) for example. I’ve only needed to set brightness for the entire strip for my projects so far
I think you should scale each value of R & G & B. For example to reduce the brightness of CRGB(250, 123, 42) by 20 percent you should multiply each number by 0.8 (and of course rounding it) it will be CRGB( 200,98,33).
Digital pixels just understand RGB, what “value” in CHSV does is basically scaling these numbers. That’s also right about setting the global BRIGHTNESS, it scales all numbers.
Floating point math (e.g. multiplying by a fraction like 0.8) will slow down your code a great deal, and it’s not needed. The FastLED “CRGB” object type already has a couple of (very) fast scaling methods on it that don’t require floating point math.
Check out this part of the FastLED pixel documentation, which discusses dimming and brightening colors specifically.
Still not sure if that’s really what was being asked for in this doc request, but now it’s turning out to be fun and teaching me a lot about the various functions, so I’ll probably keep them going no matter what you guys say
I love data visualization and added some plots of the led values/function output, which I hope is an interesting twist on explaining what’s going on.
@John_Hendy It was so nice. This way you share what you learn and also make a reference for yourself for later use. I’ll make sure to check all your posts! Keep up the good job!
@Mark_Kriegsman , thanks! Also, you’d be a good one to ask… I wasn’t happy with my method to try and show the different wave generators at the end of the post. Is there a better way to create an analog of beatsin8 using sin8, cubicwave8, etc? I just used an incrementing angle argument mapped to my strip length but it’s not as smooth as beatsin8. I ended up using a short delay, but if someone wanted a slower animation that’s still smooth, it would be glitchy at much above 5-10 ms between updates…
I plan to look at what beatsin8 is actually doing behind the scenes but figured I would also ask a veteran