LED Cube 4x4x4 and timers in tlc5490.h

I build a 4x4x4 Led cube to experimment a bit with the tlc5490s I had around.

I controll the columns 4x4 =16 (X,Y) Leds with the tlc via tlc5940.h library and each plane (Z) with an arduino port.

So far so good, Everything ok, I can set every led individually and dimm it via pwm. Brightness is also sufficient.

Since 2 planes cant have a different "pattern" while active, I tried to multiplex the planes at a higher refresh rate using a timer.

And here is my problem.

timer0 is used by the arduino code
timer1 and timer2 by the tlc5490 library

Any Ideas?

  • I could programm the atmega328 directly without the arduino framework.
  • I could,...

Thanks for ideas and help.

hi there I'm new here but... are you trying to make it pulse outputs to the LEDs (indexing through the levels of Z axis) fast enough that you can have 3 differnet X,Y patterns "simultaneously" because of the time it takes for the lights to dim?
So like one pulse it outputs the pattern on XYZ (Z=1 here), then on to a different pattern on XYZ(z=2) , and so on through Z=4? But do it really fast?

Exactly.

At a high refresh rate it will look like they are active a the same time.

Why exactly would that require a timer then, wouldn't you want something like that to execute full steam ahead?
This is probably horrible HORRIBLE logic here (but it worked for my idiotic projects so far)

But make 2 arrays (see horrible logic)
but 1, for your XYZ (a 4x4x4 array, or 5x5x5 including the null) and 1 for your Z (filled with the numbers for the differnet pins) and a var (I or something) to index through the Z array

The XYZ one would be run off of whatever code is needed for your LED driver (dunno, never seen one)
and all kinds of code would be needed to manipulate teh different values in teh XY during this idea but

void loop
{

// fill up the XYZ array by whatever means you choose


 for( I = 0; I < 4; I++)
 {
digitalWrite Z[I]; // tells which pin to output on for the Z

//Just gonna say a digitalwrite for this as well, this section should be whatever code is needed to write the info from the XYZ array to the LEDs
digitalWrite XYZ[],[],[I];
}

Basically with my idea, you fill up your array before the for loop. Then on each of the 4 ticks of the for loop it will output the 4 different tiers of the cube.

It probably wont work cause iv never tried it before (am going to look up the LED driver you linked when I get home) Or maybe someone with much more experience can come in and point you in an actual practical right direction. Maybe if I could rig something like this up to work with my shift regs at home i could do some experimenting.
(out for an hour now, driving home from school)

You are right, this works.
It would show a static picture.

If i am planning to animate this I have to write functions to fill the cube array with new content and write the Array again.
Point(), Lines() or shapes() of any kind. Calling point() and line() in a shape() would surely make sense.
And also delay()s that each figure can be recognized by the human eye.

Between all this I have to continously update/cycle the planes to multiplex, in the code a function I called update().
Wouldnt it be better to source it out to a timer, doing it regularly. In fact delay() wont work since it would stop the multiplexing aswell.
A timer would be great here aswell.

#include "Tlc5940.h"
//simple cube testing
uint8_t plane=0;
void setup()
{
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  Tlc.init();
}
uint16_t cube[4][4][4]; 

void loop()
{

for (int i=0;i<1000;i++){ // perhaps a while would be better
cube [1][1][1]=4095;
update();}
}

void update(){
/*Update function
if(plane==3){plane=0;
}else{
plane++;
}
digitalWrite(plane+4,LOW); //turn off last plane
Tlc.clear();                       //clear data from Tlc chip
int XY = 0;                        //port 0-15
for(int x=0; x<4;x++){
  for(int y=0; y<4;y++){  
    if (cube[x][y][plane]>2){           // turn on plane necessary
        digitalWrite(plane+4,HIGH);}  //turn on next plane
        Tlc.set(XY,cube[x][y][plane]); //write to Tlc (port 0-15, value matrice)
        XY++;
      }
    }
    Tlc.update();                           //update Tlc
}


void cubeFill(){
for(int z = 0; z < 4; z++)
  {
    for(int x=0; x<4;x++){
        for(int y=0; y<4;y++){
            cube[x][y][z] =4095;
            }
        }
    }
}

void cubeClear(){
for(int z = 0; z < 4; z++)
  {
    for(int x=0; x<4;x++){
        for(int y=0; y<4;y++){
            cube[x][y][z] =0;
            }
        }
    }
}

void shape2(){ 
//dot in every corner 
cube[0][0][0]=4095;
cube[0][0][3]=4095;
cube[0][3][0]=4095;
cube[0][3][3]=4095;

cube[3][0][0]=4095;
cube[3][0][3]=4095;
cube[3][3][0]=4095;
cube[3][3][3]=4095;
}

void shape4(){
//box in the middel
cube[1][1][1]=4095;
cube[1][2][1]=4095;
cube[2][2][1]=4095;
cube[2][1][1]=4095;

cube[1][1][2]=4095;
cube[1][2][2]=4095;
cube[2][2][2]=4095;
cube[2][1][2]=4095;
}

I hope you enjoyed it a bit :wink:
greets Mig