Sketch for controling 6 digit with TLC5940

Hello, can someone help please, i wanna controlling 6 digit 7 segment but stuck on how to program it on sketch… that is - to display any combination number that i want to display. how do this addresing work?

currently im controlling 2 digit just fine but with this sketch (attach) which is loong and inefficient. can someone tell me a better way of doing it?

im not so good with programming… :roll_eyes: :roll_eyes:

Simple_TLC_03.ino (24.6 KB)

You do this about 1000 times, so can’t you make it a function?

for (int x=0; x<7; x++)
{Tlc.set(x, ledA0[x]);}
for (int x=7; x<14; x++)                
{Tlc.set(x, ledB0[x-7]);}
Tlc.update();
delay(20);

Read up on C functions. Also better layout is required, there is no shortage of space.

Thanks for the responce, yes i actually read about it before - however got more confused... your answer is like answer puzzle with puzzle to me (he he) wud you gave me an example simple code with explanations? or point me to a good reference? thanks again

Well, you make a general function that does the two lots of LEDs, and takes a couple of arguments, which are which ones to do:

void setLed (int led1 [], int led2 [])
{
  byte x;
  for (x=0; x<7; x++)
    {
    Tlc.set(x, led1 [x]);
    }
  for (x=7; x<14; x++)                
    {
    Tlc.set(x, led2 [x-7]);
    }
  Tlc.update();
  delay(20);  
}  // end of setLed

Then you call it in your switch statement, like this:

    switch (switchPushCounter)
    {  
    case 0:
      setLed (ledA0, ledB0);
      break;

    case 1:
      setLed (ledA1, ledB0);
      break;

    case 2:
      setLed (ledA2, ledB0);
      break;

...

Hi Nick,
I’m afraid i still dont understand from your sample code. Trying to wrap my head around it to no avail.

You see - to my understanding if i hv 2 digit then i got this list of posibilities to display 00 - 99, which i put in an array like so:

int ledA0[] ={ 4095 , 4095, 4095, 4095, 4095, 4095, 0};
int ledA1[] ={0, 4095, 4095, 0,0,0,0};
int ledA2[] ={4095,4095,0,4095,4095,0,4095};
int ledA3[] ={4095, 4095,4095,4095,0,0,4095};
int ledA4[] ={0,4095,4095,0,0,4095,4095};
int ledA5[] ={4095,0,4095,4095,0,4095,4095};
int ledA6[] ={4095,0,4095,4095,4095,4095,4095};
int ledA7[] ={4095,4095,4095,0,0,0,0,};
int ledA8[] ={4095,4095,4095,4095,4095,4095,4095};
int ledA9[] ={4095,4095,4095,4095,0,4095,4095};
int ledB0[] ={4095,4095,4095,4095,4095,4095,0};
int ledB1[] ={0,4095,4095,0,0,0,0,0,0,0};
int ledB2[] ={4095,4095,0,4095,4095,0,4095,0,0,0};
int ledB3[] ={4095,4095,4095,4095,0,0,4095};
int ledB4[] ={0,4095,4095,0,0,4095,4095};
int ledB5[] ={4095,0,4095,4095,0,4095,4095};
int ledB6[] ={4095,0,4095,4095,4095,4095,4095};
int ledB7[] ={4095,4095,4095,0,0,0,0};
int ledB8[] ={4095,4095,4095,4095,4095,4095,4095};
int ledB9[] ={4095,4095,4095,4095,0,4095,4095};

So back to yours, how does yr first part of code can give me the same result as above? - i think im missing something but i dont know which/what. What does “byte” actually do?

Then on the second part of your code.
My understanding is, supposed i could get all the combination of which led on and off to form any digit number into the array for displaying (first part) somehow, i wud still need to “send” the data one by one with the TLc.set command right?
hence this long winded code of mine:

  • case 0:*
  • for (int x=0; x<7; x++)*
  • {Tlc.set(x, ledA0);}*
  • for (int x=7; x<14; x++) *
  • {Tlc.set(x, ledB0[x-7]);}*
  • Tlc.update();*
  • delay(20);*
  • break;*

So im also not clear how this code:
case 0:
setLed (ledA0, ledB0);
break;

can do the same thing?

i know - i wud probably take days until i can actually digest such programming, so please be patient with me

So im also not clear how this code:

    case 0:
      setLed (ledA0, ledB0);
      break;

can do the same thing?

It's a function call. I don't know how else to explain it. Read a C tutorial on calling functions (or subroutines as some people call them).

The code goes into setLed with certain parameters, setLed does its stuff, then it returns to the line after the call.