Hello all!
It's been a little while since i've had a chance to work with my arduino, real life is a head ache like that... but i have a some time now and i'm making progress.
But i have a question that i hope isn't too difficult.
Right now i have two arrays with unequal lengths.
One array represents an LED strip, and has a size of 50 integers.
the second array represents information i want to display on the led (if the program is selected)
For example
the led strip is 50 leds long (the array is 50 integers long)
my pattern is
white white white red red red blue blue blue
which will be represented as an array of integers, making the array size 9.
I want to be able to set my led array equal to the pattern array, in a repeating fashion. I hope i'm making sense.
I've included some snippets of my code below that pertain to this, but i've also attached the full enchilada below.
struct CRGB {
unsigned char b;
unsigned char r;
unsigned char g;
};
struct CRGB *leds;
#define NUM_LEDS 50
//create the LED array
int colorr[] = {
255, 255, 255, 255, 255, 255, 0, 0, 0};
int colorb[] = {
244, 244, 244, 0, 0, 0, 255, 255, 255};
int colorg[] = {
255, 255, 255, 0, 0, 0, 0, 0, 0};
//create the pattern arrays
void chasing() {
unsigned long currentInterval = 200;
unsigned long now = millis ();
static int j;
if (now - chasingStartTime >= currentInterval) // if it's time to increment
{
patternShift(colorr, colorb, colorg, 9); //this shifts the pattern so that there can be movement at a controlled speed).
chasingStartTime = now; //reset timer
}
for(int i; i < NUM_LEDS+4; i++){
if (FunctionForEachPixel (i, 7)) {
leds[i].r = colorr[i];
leds[i].b = colorb[i];
leds[i].g = colorg[i]; //leds array is has a size of 50, but colorg only has a size of 9. I'd like to repeat colorg[i] 1 though 9 for all values of leds array.
}
}
}
void patternShift(int colorr[], int colorb[], int colorg[], int arraySize) {
int tempRed;
int tempBlue;
int tempGreen;
for (int red=0; red<(arraySize -1); red++)
{
tempRed = colorr[arraySize-1];
colorr[arraySize-1] = colorr[red];
colorr[red] = tempRed;
}
for (int blue=0; blue<(arraySize -1); blue++)
{
tempBlue = colorb[arraySize-1];
colorb[arraySize-1] = colorb[blue];
colorb[blue] = tempBlue;
}
for (int green=0; green<(arraySize -1); green++)
{
tempGreen = colorg[arraySize-1];
colorg[arraySize-1] = colorg[green];
colorg[green] = tempGreen;
}
}
_6803_LED_box2_1.ino (18.6 KB)