I’ve gone through all of the examples and they work fine. I used the examples to base my code on. I was unaware of having #define and #include as the first lines in the file. I changed that with no new results. I should have mentioned that I did try a for statement but had the same results. I went back to the if statements just to have it more expanded and so I could maybe determine the problem. I did run your code and the problem persists. The first led will not light until the second one is lit. I have programmed some successful programs and not been met with this problem. Here is a copy of a program that randomly selects a color out of 7 possibilities for the 4 leds.
int randomLedColor1;
int randomLedColor2;
int randomLedColor3;
int randomLedColor4;
int lastRandomLedColor1;
int lastRandomLedColor2;
int lastRandomLedColor3;
int lastRandomLedColor4;
#include "Tlc5940.h"
#include "tlc_config.h"
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);
lastRandomLedColor1 = randomLedColor1;
lastRandomLedColor2 = randomLedColor2;
lastRandomLedColor3 = randomLedColor3;
lastRandomLedColor4 = randomLedColor4;
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);
}
Tlc.update();
delay(5000);
}
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);
}
The only thing I can think of that is different is that I’m assigning an initial value with the random function before the the leds are set. So I’ve tried assigning 0 as a value for the counter in the begin of the program and then setting it to 1 at the begin of the void loop. Still nothing. Here is a copy of that.
int counter = 0;
#include "Tlc5940.h"
void setup()
{
Tlc.init();
Serial.begin(9600);
}
void loop()
{
if (counter == 4)
{
counter = 1;
}
else
{
counter = counter + 1;
}
Serial.println(counter);
if (counter == 1)
{
setLedColor1(4095, 0, 0);
}
else
{
setLedColor1(0, 0, 0);
}
if (counter == 2)
{
setLedColor2(4095, 0, 0);
}
else
{
setLedColor2(0, 0, 0);
}
if (counter == 3)
{
setLedColor3(4095, 0, 0);
}
else
{
setLedColor3(0, 0, 0);
}
if (counter == 4)
{
setLedColor4(4095, 0, 0);
}
else
{
setLedColor4(0, 0, 0);
}
Tlc.update();
delay(5000);
}
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);
}