I'm still unsure why the delay is even needed for this program to work. I had successful programmed a series of 8 leds in a 2x4 grid to randomly light up different colors before I tried programming the running light code. It never skipped the first iteration of the loop() like the running light program. Here is a copy of that program for review.
#include "Tlc5940.h"
#include "tlc_config.h"
int randomLedColor1;
int randomLedColor2;
int randomLedColor3;
int randomLedColor4;
int randomLedColor5;
int randomLedColor6;
int randomLedColor7;
int randomLedColor8;
int lastRandomLedColor1;
int lastRandomLedColor2;
int lastRandomLedColor3;
int lastRandomLedColor4;
int lastRandomLedColor5;
int lastRandomLedColor6;
int lastRandomLedColor7;
int lastRandomLedColor8;
void setup()
{
Tlc.init();
}
void loop()
{
do
{
randomLedColor1 = random(7);
randomLedColor2 = random(7);
randomLedColor3 = random(7);
randomLedColor4 = random(7);
} while(randomLedColor1 == randomLedColor2 || randomLedColor1 == randomLedColor3 || randomLedColor1 == randomLedColor4 || randomLedColor2 == randomLedColor3 || randomLedColor2 == randomLedColor4 || randomLedColor3 == randomLedColor4 || randomLedColor1 == lastRandomLedColor1 || randomLedColor2 == lastRandomLedColor2 || randomLedColor3 == lastRandomLedColor3 || randomLedColor4 == lastRandomLedColor4);
do
{
randomLedColor5 = random(7);
randomLedColor6 = random(7);
randomLedColor7 = random(7);
randomLedColor8 = random(7);
} while(randomLedColor5 == randomLedColor6 || randomLedColor5 == randomLedColor7 || randomLedColor5 == randomLedColor8 || randomLedColor5 == randomLedColor1 || randomLedColor5 == randomLedColor2 || randomLedColor6 == randomLedColor7 || randomLedColor6 == randomLedColor8 || randomLedColor6 == randomLedColor1 || randomLedColor6 == randomLedColor2 || randomLedColor6 == randomLedColor3 || randomLedColor7 == randomLedColor8 || randomLedColor7 == randomLedColor2 || randomLedColor7 == randomLedColor3 || randomLedColor7 == randomLedColor4 || randomLedColor8 == randomLedColor3 || randomLedColor8 == randomLedColor4 || randomLedColor5 == lastRandomLedColor5 || randomLedColor6 == lastRandomLedColor6 || randomLedColor7 == lastRandomLedColor7 || randomLedColor8 == lastRandomLedColor8);
lastRandomLedColor1 = randomLedColor1;
lastRandomLedColor2 = randomLedColor2;
lastRandomLedColor3 = randomLedColor3;
lastRandomLedColor4 = randomLedColor4;
lastRandomLedColor5 = randomLedColor5;
lastRandomLedColor6 = randomLedColor6;
lastRandomLedColor7 = randomLedColor7;
lastRandomLedColor8 = randomLedColor8;
switch (randomLedColor1)
{
case 0: //red
setLedColor1(4095, 0, 0);
break;
case 1: //green
setLedColor1(0, 4095, 0);
break;
case 2: //blue
setLedColor1(0, 0, 4095);
break;
case 3: //yellow
setLedColor1(4095, 4095, 0);
break;
case 4: //cyan
setLedColor1(0, 4095, 4095);
break;
case 5: //magenta
setLedColor1(4095, 0, 4095);
break;
case 6: //orange
setLedColor1(4095, 1023, 0);
}
switch (randomLedColor2)
{
case 0: //red
setLedColor2(4095, 0, 0);
break;
case 1: //green
setLedColor2(0, 4095, 0);
break;
case 2: //blue
setLedColor2(0, 0, 4095);
break;
case 3: //yellow
setLedColor2(4095, 4095, 0);
break;
case 4: //cyan
setLedColor2(0, 4095, 4095);
break;
case 5: //magenta
setLedColor2(4095, 0, 4095);
break;
case 6: //orange
setLedColor2(4095, 1023, 0);
}
switch (randomLedColor3)
{
case 0: //red
setLedColor3(4095, 0, 0);
break;
case 1: //green
setLedColor3(0, 4095, 0);
break;
case 2: //blue
setLedColor3(0, 0, 4095);
break;
case 3: //yellow
setLedColor3(4095, 4095, 0);
break;
case 4: //cyan
setLedColor3(0, 4095, 4095);
break;
case 5: //magenta
setLedColor3(4095, 0, 4095);
break;
case 6: //orange
setLedColor3(4095, 1023, 0);
}
switch (randomLedColor4)
{
case 0: //red
setLedColor4(4095, 0, 0);
break;
case 1: //green
setLedColor4(0, 4095, 0);
break;
case 2: //blue
setLedColor4(0, 0, 4095);
break;
case 3: //yellow
setLedColor4(4095, 4095, 0);
break;
case 4: //cyan
setLedColor4(0, 4095, 4095);
break;
case 5: //magenta
setLedColor4(4095, 0, 4095);
break;
case 6: //orange
setLedColor4(4095, 1023, 0);
}
switch (randomLedColor5)
{
case 0: //red
setLedColor5(4095, 0, 0);
break;
case 1: //green
setLedColor5(0, 4095, 0);
break;
case 2: //blue
setLedColor5(0, 0, 4095);
break;
case 3: //yellow
setLedColor5(4095, 4095, 0);
break;
case 4: //cyan
setLedColor5(0, 4095, 4095);
break;
case 5: //magenta
setLedColor5(4095, 0, 4095);
break;
case 6: //orange
setLedColor5(4095, 1023, 0);
}
switch (randomLedColor6)
{
case 0: //red
setLedColor6(4095, 0, 0);
break;
case 1: //green
setLedColor6(0, 4095, 0);
break;
case 2: //blue
setLedColor6(0, 0, 4095);
break;
case 3: //yellow
setLedColor6(4095, 4095, 0);
break;
case 4: //cyan
setLedColor6(0, 4095, 4095);
break;
case 5: //magenta
setLedColor6(4095, 0, 4095);
break;
case 6: //orange
setLedColor6(4095, 1023, 0);
}
switch (randomLedColor7)
{
case 0: //red
setLedColor7(4095, 0, 0);
break;
case 1: //green
setLedColor7(0, 4095, 0);
break;
case 2: //blue
setLedColor7(0, 0, 4095);
break;
case 3: //yellow
setLedColor7(4095, 4095, 0);
break;
case 4: //cyan
setLedColor7(0, 4095, 4095);
break;
case 5: //magenta
setLedColor7(4095, 0, 4095);
break;
case 6: //orange
setLedColor7(4095, 1023, 0);
}
switch (randomLedColor8)
{
case 0: //red
setLedColor8(4095, 0, 0);
break;
case 1: //green
setLedColor8(0, 4095, 0);
break;
case 2: //blue
setLedColor8(0, 0, 4095);
break;
case 3: //yellow
setLedColor8(4095, 4095, 0);
break;
case 4: //cyan
setLedColor8(0, 4095, 4095);
break;
case 5: //magenta
setLedColor8(4095, 0, 4095);
break;
case 6: //orange
setLedColor8(4095, 1023, 0);
}
Tlc.update();
delay(200);
}
void setLedColor1(int redPin1, int greenPin1, int bluePin1)
{
Tlc.set(0, redPin1);
Tlc.set(1, greenPin1);
Tlc.set(2, bluePin1);
}
void setLedColor2(int redPin2, int greenPin2, int bluePin2)
{
Tlc.set(3, redPin2);
Tlc.set(4, greenPin2);
Tlc.set(5, bluePin2);
}
void setLedColor3(int redPin3, int greenPin3, int bluePin3)
{
Tlc.set(6, redPin3);
Tlc.set(7, greenPin3);
Tlc.set(8, bluePin3);
}
void setLedColor4(int redPin4, int greenPin4, int bluePin4)
{
Tlc.set(9, redPin4);
Tlc.set(10, greenPin4);
Tlc.set(11, bluePin4);
}
void setLedColor5(int redPin5, int greenPin5, int bluePin5)
{
Tlc.set(12, redPin5);
Tlc.set(13, greenPin5);
Tlc.set(14, bluePin5);
}
void setLedColor6(int redPin6, int greenPin6, int bluePin6)
{
Tlc.set(15, redPin6);
Tlc.set(16, greenPin6);
Tlc.set(17, bluePin6);
}
void setLedColor7(int redPin7, int greenPin7, int bluePin7)
{
Tlc.set(18, redPin7);
Tlc.set(19, greenPin7);
Tlc.set(20, bluePin7);
}
void setLedColor8(int redPin8, int greenPin8, int bluePin8)
{
Tlc.set(21, redPin8);
Tlc.set(22, greenPin8);
Tlc.set(23, bluePin8);
}