Tlc5940 7 Segment

i have posted a bit on my situation here http://arduino.cc/forum/index.php/topic,132154.0.html but havnt recieved much help in the codeing department if any one can help it is appreciated. i am making a giant 7 segment display and am having truobles with the code i do not have my rtc yet but i am trying to get the led control sorted out. i am using 9 tlc5940's the first 3 for red the second 3 for green and the last three for blue. the code i wrote so far will display the first time i set properly but when i want to change it it wont clear the old data. i have tried putting Tlc.clear(); in a number of spots but it makes it so the display does not display the whole time. here is the code so far thanks for any help

#include "Tlc5940.h"
int dim;
void setup()
{
  /* Call Tlc.init() to setup the tlc.
   You can optionally pass an initial PWM value (0 - 4095-dim) for all channels.*/
  Tlc.init();
  Tlc.clear();
  Tlc.update();
}

void loop(){
dim=0;
  time(1,22,1);
  delay(500);

}

int time(int hh, int mm, int ss){
  uint8_t fh,lh,fm,lm,fs,ls;
  fh = hh/10;
  lh = hh-fh*10;
  fm = mm/10;
  lm = mm-fm*10;
  fs = ss/10;
  ls = ss-fs*10;

  switch (fh){

  case 0:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(4+0+48, 4095-dim);
    Tlc.set(5+0+48, 4095-dim);
    Tlc.update();
    break;
    

  case 1:
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.update();
    break;

  case 2:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(4+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();

    break;

  case 3:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();
    break;

  case 4:
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(5+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();
    break;

  case 5:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(5+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();
    break;

  case 6:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(4+0+48, 4095-dim);
    Tlc.set(5+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();
    break;

  case 7:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.update();
    break;

  case 8:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(4+0+48, 4095-dim);
    Tlc.set(5+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();
    break;

  case 9:
    Tlc.set(0+0+48, 4095-dim);
    Tlc.set(1+0+48, 4095-dim);
    Tlc.set(2+0+48, 4095-dim);
    Tlc.set(3+0+48, 4095-dim);
    Tlc.set(5+0+48, 4095-dim);
    Tlc.set(6+0+48, 4095-dim);
    Tlc.update();

    break;
  
  }

  switch (lh){
  case 0:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(4+7+48, 4095-dim);
    Tlc.set(5+7+48, 4095-dim);
    Tlc.update();
    break;

  case 1:
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.update();
    break;

  case 2:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(4+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  case 3:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  case 4:
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(5+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  case 5:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(5+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  case 6:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(4+7+48, 4095-dim);
    Tlc.set(5+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  case 7:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.update();
    break;

  case 8:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(4+7+48, 4095-dim);
    Tlc.set(5+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  case 9:
    Tlc.set(0+7+48, 4095-dim);
    Tlc.set(1+7+48, 4095-dim);
    Tlc.set(2+7+48, 4095-dim);
    Tlc.set(3+7+48, 4095-dim);
    Tlc.set(5+7+48, 4095-dim);
    Tlc.set(6+7+48, 4095-dim);
    Tlc.update();
    break;

  }
  switch (fm){
  case 0:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(4+112, 4095-dim);
    Tlc.set(5+112, 4095-dim);
    Tlc.update();
    break;

  case 1:
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.update();
    break;

  case 2:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(1+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(4+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  case 3:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  case 4:
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(5+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  case 5:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(5+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  case 6:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(4+112, 4095-dim);
    Tlc.set(5+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  case 7:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.update();
    break;

  case 8:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(4+112, 4095-dim);
    Tlc.set(5+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  case 9:
    Tlc.set(0+112, 4095-dim);
    Tlc.set(1+112, 4095-dim);
    Tlc.set(2+112, 4095-dim);
    Tlc.set(3+112, 4095-dim);
    Tlc.set(5+112, 4095-dim);
    Tlc.set(6+112, 4095-dim);
    Tlc.update();
    break;

  }

  switch (lm){
  case 0:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(4+119, 4095-dim);
    Tlc.set(5+119, 4095-dim);
    Tlc.update();
    break;

  case 1:
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.update();
    break;

  case 2:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(1+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(4+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  case 3:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  case 4:
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(5+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  case 5:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(5+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  case 6:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(4+119, 4095-dim);
    Tlc.set(5+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  case 7:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.update();
    break;

  case 8:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(4+119, 4095-dim);
    Tlc.set(5+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  case 9:
    Tlc.set(0+119, 4095-dim);
    Tlc.set(1+119, 4095-dim);
    Tlc.set(2+119, 4095-dim);
    Tlc.set(3+119, 4095-dim);
    Tlc.set(5+119, 4095-dim);
    Tlc.set(6+119, 4095-dim);
    Tlc.update();
    break;

  }


  switch (fs){
  case 0:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(4+32, 4095-dim);
    Tlc.set(5+32, 4095-dim);
    Tlc.update();
    break;

  case 1:
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.update();
    break;

  case 2:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(1+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(4+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  case 3:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  case 4:
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(5+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  case 5:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(5+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  case 6:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(4+32, 4095-dim);
    Tlc.set(5+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  case 7:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.update();
    break;

  case 8:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(4+32, 4095-dim);
    Tlc.set(5+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  case 9:
    Tlc.set(0+32, 4095-dim);
    Tlc.set(1+32, 4095-dim);
    Tlc.set(2+32, 4095-dim);
    Tlc.set(3+32, 4095-dim);
    Tlc.set(5+32, 4095-dim);
    Tlc.set(6+32, 4095-dim);
    Tlc.update();
    break;

  }
  switch (ls){
  case 0:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(4+39, 4095-dim);
    Tlc.set(5+39, 4095-dim);
    Tlc.update();
    break;

  case 1:
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.update();
    break;

  case 2:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(1+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(4+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();
    break;

  case 3:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();
    break;

  case 4:
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(5+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();
    break;

  case 5:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(5+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();
    break;

  case 6:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(4+39, 4095-dim);
    Tlc.set(5+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();
    break;

  case 7:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.update();
    break;

  case 8:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(4+39, 4095-dim);
    Tlc.set(5+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();
    break;

  case 9:
    Tlc.set(0+39, 4095-dim);
    Tlc.set(1+39, 4095-dim);
    Tlc.set(2+39, 4095-dim);
    Tlc.set(3+39, 4095-dim);
    Tlc.set(5+39, 4095-dim);
    Tlc.set(6+39, 4095-dim);
    Tlc.update();

    break;

  }

}

when i want to change it it wont clear the old data.

That is because your code only sets the LEDs for the digits, it never turns any off.
While your code is very long winded and not the way to do it anyway, it needs to have all seven segments addressed in each case of a digit not just those that are going to be turned on.

i have figured it out i put Tlc.clear(); before the first switch and Tlc.update(); after the last one

I'm doing something similar. I tried use a clear code but it caused flicker, because each time the program loops it turns off the segments that would stay on for the case statement and back on. The way Grumpy Mike is talking about leaves the segments that need to be on and the ones that need to be off to stay in that state until the switch case changes.

To Grumpy Mike, I am looking for a better way to display 7 segments any links to code would be appreciated

I am looking for a better way to display 7 segments any links to code would be appreciated

This tells you what you need to do using arrays.
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

Grumpy Mike, Thanks for the link, this looks like it will shorten up my supper long code.

Mike, the code I've been working on is for three seven segments displayed on a TFT LCD display but its pretty lengthy. What is the best way to write the to code for the firth 7 segment display to count 0 to 9 then add 1 to the second 7 segment display and after it counts 0to 9 and then add 1 to the third 7 segment display and so on.

another words, some type of shift register code that will count pulses for the first digit then generate a pulse after 10 pulses for the second digit and so on for the third digit. (ones place, tens place and hundreds place).

Well that is not the way you count traditionally.
The simplest way is using if statements based on the total count. Keep a running total and then use a sequence of if statements to sort out the number to display. This will involve adding ten or one hundred depending if you want to increment the second or third digit. If I have understood your requirements correctly.

Not sure on how to word it, but I guess what I'm looking for is how to separate the ones place, tens place and hundreds place. this is not going to be worded right but if for say "Num = Count++" and "A= ones place of Num", "B= Tens place of Num" and "C= Hundreds place of Num"

I done something like A = 375 rounded down to the nearest hundreds =300 B =375 - 300 =75 rounded to the nearest tens = 70 and C= 75 - 70 = 5 A=3 B=7 C=5 in excel but not sure hoy to do it with arduino.

Thanks in advance

Just use a divide.
If a = 1234
Then a/1000 = 1
To get at the others use the remainder operation %
So a% 1000 = 234
Chip away at the number.

Mike, Thanks so much, Not sure I got it coded right, but this works.

void setup(){
  Serial.begin(9600);
  
}
int A = 0;
int B = 0;
int C = 0;
int D = 0;
int E = 0;
int F = 0;
int G = 0;

void loop(){
 
 Serial.println("     ");
  Serial.print("  A   ");
 Serial.print(A);
  Serial.print("  B   ");
  Serial.print(B);
  Serial.print("   C  ");
  Serial.print(C);
   Serial.print("  D   ");
   Serial.print(D);
   Serial.print("  E   ");
   Serial.print(E);
   Serial.print("  F   ");
   Serial.print(F);
   Serial.print("  G   ");
   Serial.print(G);
  
  A ++;
  delay (500);
  
  B = A %100;
  C = A %10;
  D = A %1;
  E = (A - B) * .01;
  F = (B - C) * .1;
  G = C - D; 
 /code]

This is a better display in serial monitor. I also put the whole number back together "H = (E100)+(F10)+G

void setup(){
  Serial.begin(9600);
  
}
int A = 0;
int B = 0;
int C = 0;
int D = 0;
int E = 0;
int F = 0;
int G = 0;
int H = 0;
void loop(){
 
 Serial.println("     ");
  Serial.print("    A ");
 Serial.print(A);
  Serial.print("    B ");
  Serial.print(B);
  Serial.print("    C ");
  Serial.print(C);
   Serial.print("    D ");
   Serial.print(D);
   Serial.print("    E ");
   Serial.print(E);
   Serial.print("    F ");
   Serial.print(F);
   Serial.print("    G ");
   Serial.print(G);
   Serial.print("    H ");
   Serial.print(H);
  
  A ++;
  delay (500);
  
  B = A %100;
  C = A %10;
  D = A %1;
  E = (A - B) * .01;
  F = (B - C) * .1;
  G = C - D;
  H = (E * 100) + (F * 10) + G; 
 }