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)
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.
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.
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.
@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);
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?