Hi, how exactly can I set a variable for preset colors? I’m trying to do something like this.
Variable = CRGB( 255, 90, 0)
But when I reference the variable in the program, it doesn’t seem to work, It doesn’t light up the led at all.
Hi, how exactly can I set a variable for preset colors? I’m trying to do something like this.
Variable = CRGB( 255, 90, 0)
But when I reference the variable in the program, it doesn’t seem to work, It doesn’t light up the led at all.
What method are you using to turn your LED(s) on in the color you defined?
Try plugging your preset color into the fill_solid function:
fill_solid(leds, NUM_LEDS, Variable);
…where “Variable” is the CRGB color you referenced in your post. This should set the value of each LED to your desired color and ‘show’ that color with a single call.
Forgive me, I’m pretty new at this and mostly learning from samples.
Originally I was using this in a for loop
leds[i] = CRGB( 255, 90, 0);
I could probably use the fill_solid with the number of leds instead of using a loop.
But how exactly should I define the variable?
I tried this
int color = CRGB( 255, 90, 0);
But it doesn’t seem to work.
I just tried that with
fill_solid(leds, 1, color);
and it didn’t seem to work. What might I be doing wrong?
Assuming your hardware is properly configured (with the necessary corresponding definitions/declarations in your code), then try this and see if your LEDS light up:
fill_solid(leds, NUM_LEDS, CRGB(255, 90, 0));
FastLED.show();
Using that works, but if I try to use the variable, it doesn’t seem to work.
Instead of
int color = CRGB( 255, 90, 0);
try this:
CRGB color = CRGB( 255, 90, 0);
Your variable isn’t an int. Its a CRGB color. This should help.
I don’t know why I didn’t think of that! Thank you, that works.
I guess I was just thinking that because you could also use hex that int might work. Told you I’m new to this. Lol
Well, you could also use an integer, but you need a wider one to hold all the bits of a color. On AVR-based Arduinos:
“int” is fifteen bits plus a sign
“unsigned int” is sixteen bits
CRGB needs 24 bits (8 each for R G and B)
“unsigned long int” is 32 bits
“uint32_t” is a shorter way to type the same thing
So you could use uint32_t, but at 32 bits, that’s actually bigger (and slower) than the 24 bits that it needs to be. “CRGB” is actually smaller and faster than an integer in this case!