I have two arrays.
One is an incoming data stream stored as a single dimensional array.
for (uint16_t i = 0; i < 300; i++) SingleArray[i]= 0; // turn all Red LEDs ON for (uint16_t i = 0; i < 300; i+=3) SingleArray[i]= 20;
The Other is a multidimensional array for RGB lighting
as used by Alan Burlison in his WS2811 routine:
typedef struct __attribute__ ((__packed__)) { uint8_t g; uint8_t r; uint8_t b; } RGB_t;
I want to set all the red LEDs to a known value:
// Create RGB Arrays using the RGB_T structure RGB_t rgb1[50]; for (int j = 0; j < 50; j++) { rgb1[j].r = SingleArray[j]; rgb1[j].g = SingleArray[j+1]; rgb1[j].b = SingleArray[j+2]; }
The single array is 3 times as big as the RGB array.
What I am trying to do is Set rgb1[j].r = 20 while rgb1[j].g and rgb1[j].b remain set to 0.
the results of the above is:
Pixel1 red
Pixel2 Green
Pixel3 Blue
Pixel4 red
Pixel5 Green
Pixel6 Blue
Pixel7 red
Pixel8 Green
Pixel9 Blue
etc
If I use
for (int j = 0; j < 50; j++) { rgb1[j].r = 20; rgb1[j].g = 0; rgb1[j].b = 0; }
I get the result I want.
So where am i going wrong? or what is a better way of achieving the same result?
Any help will be greatly appreciated, if only so I can get some restful sleep.