Hello... I have a daft/dumb question, but I am pulling my hair out.

Hello… I have a daft/dumb question, but I am pulling my hair out.

I’m trying to assign a colour to an LED based on a predefined hex code ultimately from processing]. However I cannot work out how to take a predefined variable and assign it to an LED colour:
void loop() {

    inputColor = "0x00FF00";
    leds[0] = CRGB(inputColor); FastLED.show();
    Serial.println (inputColor);

I have tried every which way under the sun, as an “int”, “char”, “string”, nothing seems to work, any ideas what I might be doing wrong?

Thank you in advance, my project is literally not even off the ground with this one :slight_smile:

Try… leds[0] = 0x00FF00;

Thanks for the speedy reply… I need to use an external variable [from processing]. I think I’ve overcome this hurdle using “unsigned long” to declare inputColor, it seems to work, but I am not sure if this is right… any ideas?


Yep. JP is exactly right: this is a number, not a string. In this case, you’re referring to the six-digit hex number 00FF00, and the 0x in front just tells the compiler that this is a hex number, not decimal. (e.g. 1234 is assumed to be decimal, 0x1234 means that it should be treated as hexadecimal, which is 4660 in decimal – a really different number!)

0x00FF00 is the same number as 65280 (decimal).

If you’re passing these values into FastLED from Processing over a serial connection from a computer, you’ll need to make sure that if you’re sending strings from Processing, that you have some code in place on the Arduiono side to parse the strings into actual numbers. And in that case, you won’t need to transmit (or parse) the leading “0x” characters.

ok, I can try that, at this stage I was just entering values into the serial monitor. I can get processing to o/p decmal numbers instead… it might make things easier reading to/from the serial monitor.

Thank you for your help, if you have any further advice it’d be super appreciated.

Happy to help-- let us know how it goes!

The big thing is the difference between a string of characters like “1”, “2”, “3”, “4” and the actual number 1234. At some point, your Arduino code will have to “parse” the incoming characters that it reads from Serial and assemble them into an actual number. There’s lots of code out there to do that, look around and see if you can find some number parsing code for Arduino that you like.

I see, when I am using “unsigned long” it is still a number, I’m not actually using a string. Is it possible to set the color value with a text string, or does it need to be a number?

Internally, it’s all numbers.

You’ll need to use a string-parsing function to turn the string of characters into an actual number.

OK, so now I am making progress, using decimal numbers and CRGB(inputColor), I can use any unsigned int.Sorted.

ps legends, thank you, probably lots more annoying queries to follow.

Excellent! Eager to see what you’re building, too…

Hi @Nick_Diacre i wanted to pass in web style hex values to FastLED - here is some example code (its not a full sketch) based on what i learned, to help your thought process:

I read out the colour of a pixel (led[0]), and convert it to Hex, then print it out as a string, but also change its colour based on a value.


Hope this helps you.

thanks stuart, it has been built with the help of @focalintent on the gitter… amazing how something so simple was so blooming annoying, but mr.intent nailed it. I have a small 3 way system running, but it will be expanded, hopefully into a 12 way system mounted in a weird scultpture thingy. photo of tonights work to follow :slight_smile: thank you all, what an amazing community.