Setting neopixel color with function

I’m using ws2812fx for the pixel strip…

This is how I setting the color:
ws2812fx.setColor(flashColor);

Here is my function code:

int setColor(String command)
    {
        unsigned long cmd = strtol(command, NULL, 64);
        if(cmd >= 0 && cmd <= 0xffffff)
            {
                flashColor = cmd;
            }
        return flashColor;
    }

I can get blues and greens but if I put values for red they aren’t taking, i.e. “ff0000” should be RED

Cleaned things up a bit, but it didn’t help…


int flashColor = 0xff6700;

Particle.function("lightColorHex", setColor);

int setColor(String command)
    {
        int cmd = (int)strtol(command, NULL, 32);
        if(cmd >= 0 && cmd <= 0xffffff)
            {
                flashColor = cmd;
            }
        return flashColor;
    }

I misunderstood the syntax of strtol the last parameter isn’t bits, it’s the base

Changed my code to this…

int cmd = (int)strtoll(command, NULL, 0);

…and now it works, but I do have to put the values in with “0x” at the front which is fine “0xff00ff” now shows up as violet

As you found out strtol() takes the base, so when you know you will pass HEX numbers you can set the base as 16 - this way you should not need the 0x