Multiplexing, chip switches color slower than pins switches lights. compensate?

So, i have tlc5940 running two rgb LEDs using three of its pwm outs. the anodes are switching at the same time in the code, but theyre a little faster when actually running it, so the colors blend together. I would upload a schematic, but all TLC5940 circuits are pretty much the same and i dont think its relevant any way.
With my code, i've tried putting the delay between the switch and it solves the blending problem, but the led duty cycle becomes so low the light is barely visible. ive tried every order of tlc.update, digitalWrite(6, high)/(7, low) or vice versa. nothing seems to change the issue but the delay. and the delay is not a good way to solve a problem. I'm very new at programming, so if you spot something out of order let me know.

i also took some pictures of the leds and it shows exactly whats going on down to the microsecond. Even with a 1 second delay, i could see the flicker of the red on the blue side and bleu on the red side.

this is a 1ms delay, you can see that red and blue mixed entirely:

this is a 5ms delay, there is still a bit of each color on the wrong side:

this is a 25ms delay. still, there is about 1ms of the wrong color on each side:

Here's the code:

#include <Tlc5940.h>   // TLC5940 library
void setup() 
{
 Tlc.init(0);         // initialize tlc5940
 pinMode(6, OUTPUT);  // set the anode pin of led one to output
 pinMode(7, OUTPUT);  // set the anode pin of led two to output
}
void loop() 
{
 int l = 16;          // brightness factor 1 to 16
 int r = 2;           // tlc5940 pin 2 is for red
 int g = 1;           // tlc5940 pin 1 is for green
 int b = 0;           // tlc5940 pin 0 is for blue
 Tlc.set(r, 255 * l); // set red 0 to 255 with brightness l
 Tlc.set(g, 0 * l);   // set green 0 to 255 with brightness l
 Tlc.set(b, 0 * l);   // set blue 0 to 255 with brightness l
 delay(0);            // delay, too small and the colors mix, too long and it gets blinky
 digitalWrite(6, 1);  // turn on led one
 digitalWrite(7, 0);  // turn off led two
 Tlc.update();        // send updated information to the chip
 Tlc.set(r, 0 * l);   // set red 0 to 255 with brightness l
 Tlc.set(g, 0 * l);   // set green 0 to 255 with brightness l
 Tlc.set(b, 255 * l); // set blue 0 to 255 with brightness l
 delay(0);            // delay, too small and the colors mix, too long and it gets blinky
 digitalWrite(7, 1);  // turn on led two
 digitalWrite(6, 0);  // turn off led one
 Tlc.update();        // send updated information to the chip
}

so how do i correct for this, or is there another way i should be doing it?

I'm running this on the arduino mega 2560
I used the TLC5940 library
I used this for which pins go where: Google Code Archive - Long-term storage for Google Code Project Hosting.

is there another way i should be doing it?

You should begin with ditching the useless curly braces. You CAN change the value of a variable. You do NOT need to create a new variable.

[/quote

PaulS:
You should begin with ditching the useless curly braces. You CAN change the value of a variable. You do NOT need to create a new variable.

fixed that. maybe it runs faster but it looks less organized to me. no improvements yet on the color mixing issue

fixed that.

By f**king with the first post? I'm out of here.

PaulS:
By f**king with the first post? I'm out of here.

the code does the exact same thing. this code doesnt do what i want it to. changing it wont do anything. i need to rewrite it. entirely different. obviously what im doing doesnt work and im asking for help figuring it out. dont expect me to do everything right. the whole fucking reason im on this forum is because i dont know what im doing.
leave, youre f*cking useless anyway.

My point was that this thread is SUPPOSED to be a history of what you have done. By changing the code in the first post, you have destroyed that historical record. No one can look at the code in various threads to see what you have changed.

Hi,
In your circuit have you got the TLC5940 ICs bypassed at their power supply pins.
Is your power supply able to provide the current needed to run them.

Tom..... :slight_smile: