RGB cube 4x4x4 TLC5940

Hello all, I have finished the hardware of my 4x4x4 RGB led and am working with the code now. The setup is as follows.

Each level of the cube "z axis" is connected through 2n2222's to 4 i/o pins of the arduino. (this allows me to turn on a level of the cube)

Then each r g and b lead of the leds are connected downward though the cube to a pin on the TLC chips (3 tlcs are used).

I have developed this simple code to address a location on the cube and turn on an led

#include "Tlc5940.h"

int z = -1;       //initalize z axis as -1 this would normally be 0,1,2,3 for the 4 z layers of the cube
int x = -1;       //initalize x axis as -1 this would normally be 0,1,2,3 for the 4 x addresses of the cube
int y = -1;       //initalize y axis as -1 this would normally be 0,1,2,3 for the 4 y addresses of the cube
int zpin0 = 4;   //to set the I/O pins for z values
int zpin1 = 5;
int zpin2 = 6;
int zpin3 = 7;

void setup()
{
  pinMode(zpin0, OUTPUT);  //set outputs for z levels of cube
  pinMode(zpin1, OUTPUT);
  pinMode(zpin2, OUTPUT);
  pinMode(zpin3, OUTPUT);
  Tlc.init();  //initalize TLC5940 chips

}

// input would be (4095,4095,4095,0,0,0)
// this is        (r,g,b,x,y,z)
void led(int r, int g, int b, int x, int y, int z)
{
  int channel = -1; //initalize channel as -1 so when we add 1 we are at the first input on TLC chip
  Tlc.clear();
  digitalWrite(zpin0, LOW);
  digitalWrite(zpin1, LOW);
  digitalWrite(zpin2, LOW);
  digitalWrite(zpin3, LOW);
  //^^^^^^this is setting everything to low to clear last use of cube
  
  switch(z)  //turn on proper level of cube with zpin
  {
    case 0:
      digitalWrite(zpin0, HIGH);
      break;
    case 1:
      digitalWrite(zpin1, HIGH);
      break;
    case 2:
      digitalWrite(zpin2, HIGH);
      break;
    case 3:
      digitalWrite(zpin3, HIGH);
      break;
  }
// channel starts as -1 then we change that to the pin we want to access in the cube minus 1
// then we add 1 2 or 3 to the channel to get the led we want
channel +=(x*3+y*12); // This is a forumla to access the first pin (blue) of the rgb led on any point in the cube
Tlc.set(channel+3,r); //2pin add 3 to channel to get red led
Tlc.set(channel+2,g); //1pin add 2 to channel to get green led
Tlc.set(channel+1,b); //0pin add 1 to channel to get blue led
Tlc.update();
delay(3);
}

void loop()
{
//r,g,b,x,y,z
led(4000,0,0,0,0,0);

led(4000,0,0,3,3,3);
}

This should turn on the red led at location 0,0,0 and the red led at location 3,3,3 (its hard to visualize but this is the lowest level of the cube and the highest level of the cube kiddy corner to each other)

This works perfectly except on problem, i'm getting bleed over into 0,0,3 and 0,3,0. (these are the upper and lower leds of the 2 im trying to turn on)

I have uploaded this Arduino 4x4x4 rgb cube - YouTube
In the video i have increased the delay in my function to 100 when it runs at 3 there is no flickering at all.

My hope is that this can be corrected in the software somehow, if it cannot than i would have to build a board and put a bunch of shift registers on it this would not be fun :frowning:

Any help you guys can give as to how i might be able to revise or rework my code so it will not bleed like this would be so useful.

I should specify that the front bottom left and far top right leds are the only ones that should be lighting up, but as you can see 2 other leds are lighting also