I've been using FastLED for a while now,

I’ve been using FastLED for a while now, but mostly with legacy code that just uses it to set pixel colours, and all the clever stuff is done with my own older code.

I want to try using the superior FastLED functions, but am falling at the first hurdle.

I’d expect…

CRGB custCol = CRGB(255, 0, 0);

to make custCol be 0xFF0000, but instead it’s always 0x000001. In fact it’s 1 no matter what I put in.

What am I doing wrong? (Please note that I am not looking for red specifically, and so I know that in this case I can use CRGB::Red)

Thanks

I think this is a misunderstanding of what CRGB is, and how it works.

CRGB is an object in programming parlance, a container of data and functions to act on that data. It has no meaning to say it is always 1. Instead, you need to extract internal data to see what is going on. In this case, custCol.r would be 255, while custCol.b and .g would be 0.

I’m sure there is a better explanation, but it’s both simple and complicated. C++ can do that to you.

Thanks Peter. I don’t think my question is as clear as it could be.

why would

CRGB custCol1 = CRGB(255, 0, 0);
CRGB custCol2 = CRGB::Red;

Serial.print(custCol1); Serial.print(" - "); Serial.println(custCol2);

print out “1 - 16711680”?

16711680 is 0xFF0000, as I’d expect. I’d also expect the ‘1’ to be 16711680.

How do I get custCol1 to become the value that I want it to based on an R, a G and a B value?

Thanks.

As I look through the code, I don’t see an exact reason. I suspect it’s because CRGB::Red is 0xFF0000 while CRGB(x,y,z) is in turn converted before it is assigned. Though I don’t see where that would happen in the CRGB object.

Why do you want that value in that way?

Because I’m using a mixture of old non-FastLED code and FastLED code, and I need to convert some RGB values to a FastLED colour that can be used in a palette definition.

It would require a total rewrite to do it properly in native FastLED.

Thanks anyway, though.

You can’t print them.
They get printed as numbers but that’s not their actual value.

Try printing custCol.red and custCol.green and custCol.blue.

@Mark_Ortiz , wait, why does custCol2 print out as 16711680 for you? When I used what you posted:
CRGB custCol1 = CRGB(255, 0, 0);
CRGB custCol2 = CRGB::Red;
Serial.print(custCol1); Serial.print(" - "); Serial.println(custCol2);

I get a print out of:
1 - 1

What controller are you using?

Different answers on 8- and 32- bit controllers :slight_smile:

Gotta love “C”.

I’m using a Teensy 3.0 :slight_smile:
Thanks Mark.

Using Arduino Due. @Mark_Kriegsman ​ can we forget about printing out values. I was just trying to illustrate a point. All I want to know is how to get a colour from 3 separate R G B values that are suitable for a palette array.) Or does that particular function not work on a Due the way it is meant to?

I solved this myself, the old fashioned way…

custPaletteCol = customColour1_B + (customColour1_G * 256) + (customColour1_R * 65536);

Thanks anyway everyone.