I am trying to drive a Neopixel strip from a 16MHz 5V Adafruit Trinket
I have a button to cycle around off, white, red, green & blue, so I want to store those five options as RGB values
In my code, I have (I’ve snipped out the irrelevant parts)
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
...
//colour array (OFF/WHITE/RED/GREEN/BLUE)
uint16_t colour[][3]{ {0,0,0}, {255,255,255}, {255,0,0}, {0,255,0}, {0,0,255}};
Is uint16_t
the right array type for the colour[][3] array?
Then a function that’s called via callbacks, when the pixels need a colour or brightness change
void renewStrip(float b, int c){ //b=brightness factor from 0.1 to 1 & c = index to colour array, containing colour RGB values
for (int pixel = 0; pixel < strip.numPixels(); pixel++){
// strip.Colour(R,G,B) converts the three uint8_t RGB values in the indexed colour array into a combined colour value for strip.Color
strip.setPixelColor(pixel, strip.Color(colour[c][1]*b,colour[c][2]*b,colour[c][3]*b));
}
strip.show();
}
Setup has the following
void setup() {
...
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
//strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}
I presume that when I call on the array, with strip.Color(colour[c][1],colour[c][1],colour[c][1])
, the colour array will return the r, g & b values into the Neopixel.Color
method that will generate a uint32_t
combined r, g & b value that can be consumed correctly by the second parameter of the Neopixel.setPixelColor
method?
Are my presumptions correct? Is there a better approach? Types in multidimentional arrays – what’s going on?