#Define , RGB colors for NeoPIxel

Am playing with the NeoPixels. Have got example code up an running which spins the neopixels through different colors. However a little confused on how to extend this, particulary with the way it has defined the neopixel colors.

The sketch defines the colors as so

#define BLUE 5,5,190
#define WHITE 150,150,150
#define GREEN 10,180,10

and calls the following function Spin in this fashion

spin (BLUE);

void spin(int R, int G, int B) {
     for(i=0; i < PIXEL_COUNT; i++) {
         strip.setPixelColor(i, R,G,B);
     for(i=0; i < PIXEL_COUNT; i++) {
         strip.setPixelColor(i, 0,0,0);

I want to send the Photon commands to change the color, so need to set a variable equal to one of the defined colors and pass to the spin function.
However, setting the variable to Int fails ie

int lightcolor = BLUE;

I have also tried an array

int lightcolor [] = BLUE;

this fails as well.

i managed to get
int lightcolor [1,1,1] = BLUE

to pass the compiler, but it failed on the functional call



just not sure what I am missing here with regard to how the #define declares that const and how to use it throughout the sketch


A #define macro is just inserted as is via a preprocessor into the code before compiling.
i.e. your spin (BLUE); would be converted by the preprocessor into spin (5,5,190); and that also shows how you’d need to pass the data when not using macros.

Your other attempts would render to

//int lightcolor = BLUE;
int lightcolor = 5,5,190;

//int lightcolor [] = BLUE;
int lightcolor [] = 5,5,190;

//int lightcolor [1,1,1] = BLUE
int lightcolor [1,1,1] = 5,5,190
1 Like