1

I am using a led strip WS2812b, an ESP8266 (NodeMCU 1.0) and a gesture sensor APDS9960. I want that when I move my hand from left to right and from right to left I change the colors of the strip of leds, previously saved in an array of strings:

const char * colors [11] = {"CRGB :: White", 
"CRGB :: WhiteSmoke", 
"CRGB :: CadetBlue", 
"CRGB :: SteelBlue", 
"CRGB :: Teal", 
"CRGB :: SlateGray" , 
"CRGB :: MediumPurple", 
"CRGB :: Purple", 
"CRGB :: PapayaWhip", 
"CRGB :: LightPink", 
"CRGB :: Crimson"};

But when I'm going to turn on the colors using the functions of the FastLed library in this way:

for (int i = 0; i <NUM_LEDS; i = i + 1) {
       leds [i] = colors [2];
       FastLED.show ();
       delay (10);}

All I get is this error:

invalid conversion from 'const char *' to 'uint32_t {aka unsigned int}' [-fpermissive]

I guess the problem is me when declaring the array, could someone help me?

3

You don't want an array of strings containing the (badly formatted) names of variables. Instead you want an array of 32-bit integers containing the values held within those variables.

const uint32_t colors[] = {
    CRGB::White, 
    CRGB::WhiteSmoke, 
    CRGB::CadetBlue, 
    CRGB::SteelBlue, 
    CRGB::Teal, 
    CRGB::SlateGray, 
    CRGB::MediumPurple, 
    CRGB::Purple, 
    CRGB::PapayaWhip, 
    CRGB::LightPink, 
    CRGB::Crimson
};

Since colours are just numbers, in the (hexadecimal) form of 0xRRGGBB you just store them as 32-bit unsigned integers. The names you have there are just such (constant) variables used for easy reference (CRGB::White is 0xFFFFFF).

  • Thanks!!! Your recomendation did the work correctly!!! Thanks again!!! – k.Cyborg Sep 27 '18 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.