Hi i'm trying to set my leds with the single hex color code varriant.

Hi i’m trying to set my leds with the single hex color code varriant.

I ’ ve stored my data in a String and try to past that to my leds.
but for some reason i can’t get the colors to change…

code:
void setFairyQueenColors (String head, String chest, String robe)
{
String a = “0x”;
a = a + head;
String b = “0x”;
b = b+ chest;
String c = “0x”;
c = c+ robe ;

Serial.println(“debug fairyqueencolors”);

Serial.println(a) ;
Serial.println(b);
Serial.println(c);

    leds[0] = 'a';
    leds[1] = 'b';
    leds[2] = 'c';
    FastLED.show();

Serial.println(“debug leds”);

Serial.println(leds[0]) ;
Serial.println(leds[1]);
Serial.println(leds[2]);
}

returns on serial monitor :

debug fairyqueencolors
0xF78CFF
0xFFFFFF
0x87ABFF
debug leds
1
1
1

any advice?
thx in advance
Kristof

Thanks for asking here – these are good getting-started questions.

There is no automatic conversion from strings to numbers in C/C++. So the code you posted is dealing all with strings, but then trying to assign them into places that required numbers (i.e., the led array). Also, you had quotes around what you were assigning into the leds, so instead of trying to assign the value of the variable A into an led, you the code was setting the led to the actual letter A.

Instead of using strings at all, try just using numbers throughout the entire program, more like this. “unsigned long” is a number wide enough to hold an RGB color code:

void setFairyQueenColors (unsigned long head, unsigned long chest, unsigned long robe)
{
unsigned long a = head;
unsigned long b = chest;
unsigned long c = robe ;

Serial.println(“debug fairyqueencolors”);

Serial.println(a) ;
Serial.println(b);
Serial.println©;

    leds[0] = a;
    leds[1] = b;
    leds[2] = c;
    FastLED.show();

Serial.println(“debug leds”);

Serial.println(leds[0]) ;
Serial.println(leds[1]);
Serial.println(leds[2]);
}

You can call this like this:
setFairyQueenColors( 0xF78CFF, 0xFFFFFF, 0x87ABFF )

No quotes are needed, because C understands these hexadecimal codes directly as 32-bit numbers.

Here’s an even simpler way: instead of “unsigned long”, just use FastLED’s “CRGB” color data type:

void setFairyQueenColors (CRGB head, CRGB chest, CRGB robe)
{
leds[0] = head;
leds[1] = chest;
leds[2] = robe;
FastLED.show();
}

You can then call that function with any arguments that are convertible to CRGB values, i.e., this still works:
setFairyQueenColors( 0xF78CFF, 0xFFFFFF, 0x87ABFF );
But now these work, too:
setFairyQueenColors( CRGB( 120,140,255), CRGB(255,255,255), CRGB(140, 171, 255 ));
and
setFairyQueenColors( CRGB::Pink, CRGB::White, CRGB::PeachPuff);
// All standard HTML color names are supported

Let us know how it goes! I’m sort of dying to find out what the FairyQueen is all about :smiley:

thnx for the quick response, i’m gonna study your answer a little more to see how it turns out, The fairyqueen is a part of a led chandelier that i’m building with lots of fairies and a queen ofcourse ;).

In C, “double quotes” denote a string, and 's’ingle quotes denote a char…

Either way, you never quote variable names.

Oh lol, I totally misread the intent of the code.

@Mark_Kriegsman already answered it :slight_smile:

thnx anyway, that part of the code works now ;), i solved it to converted my strings to unsigned longs like mark said!