4x4x4 LED Cube Arduino Display Driver

Display driver code for lighting 1-64 LEDs in 4x4x4 cube.

 
/*
  4x4x4 LED Cube
  Connection Setup: 
  Columns
  [(x,y)-Pin]
  (1,1)-13
  (1,2)-12
  (1,3)-11
  (1,4)-10
  (2,1)-9
  (2,2)-8
  (2,3)-7
  (2,4)-6
  (3,1)-5
  (3-2)-4
  (3-3)-3
  (3,4)-2
  (4,1)-1
  (4,2)-0
  (4,3)-A5
  (4,4)-A4
  Layers
  [layer-Pin]
  a-A0
  b-A1
  c-A2
  d-A3

  JOYSTICK CONTROL
  VRX - A5
  VRY - A7
  JSW - D21 (VRZ SIKE :-)  (o'v'o)
  
*/
//bool thing[64]
//initializing and declaring led rows
  int column[16]={15,14,13,12,11,10,9,8,7,6,5,4,3,2,17,16};
//initializing and declaring led layers
  int layer[4]={A3,A2,A1,A0};
 
int time = 250;
bool test[64];
int jsw = 21;
int vrx = A7;
int vry = A5;

int returnDir(){
  int x;
  int y;
  //Z MAP
  //  0 1 2 
  //  3 4 5
  //  6 7 8
  int z;
  int w;
  x = analogRead(vrx);
  //Serial.print("x value: ");
  //Serial.print(x);
  //Serial.print("  ");
  y = analogRead(vry);
  //Serial.print(" y value: ");
  //Serial.println(y);
  if(x > 682){
    z = 0;
  }
  if(x > 341 && x < 683){
  z = 1;
  }
  if(x < 342){
  z = 2;
  }
  if(y > 682){
  w = 2;
  }
  if(y > 341 && y < 683){
  w = 1;
  }
  if(y < 342){
  w = 0;
  }
  return 3*w+z;
}

void setup()
{
  //setting rows to ouput
  for(int i = 0; i<16; i++)
  {
    pinMode(column[i], OUTPUT);
  }
  //setting layers to output
  for(int i = 0; i<4; i++)
  {
    pinMode(layer[i], OUTPUT);
  }
  //seeding random for random pattern
  //randomSeed(analogRead(10));

  for(int i = 0; i<64; i++){
    test[i] = 0;
  }
  pinMode(vrx, INPUT);
  pinMode(vry, INPUT);
  pinMode(jsw, INPUT);
  Serial.begin(9600);
  
}
    
void turnEverythingOff()
 {
   for(int i = 0; i<16; i++)
   {
     digitalWrite(column[i], 1);
   }
   for(int i = 0; i<4; i++)
   {
     digitalWrite(layer[i], 0);
   }
 }
  

void turnEverythingOn()
{
  for(int i = 0; i<16; i++)
  {
    digitalWrite(column[i], 0);
  }
  //turning on layers
  for(int i = 0; i<4; i++)
  {
    digitalWrite(layer[i], 1);
  }
}
 
void OneOn(int x, int y, int z)
{
  digitalWrite(layer[z],1);
  for (int i=0; i<16; i++)
  {
    digitalWrite(column[i],1);
  }
  digitalWrite(-4*x-y+20, 0);
}

void Light(bool leds[64], int dur){
  for (int j=0; j<ceil(dur/10); j++){
   for (int i=0; i<64; i++){
    if (leds[i]){
      digitalWrite(column[i%16],0);
      digitalWrite(layer[int(floor(i/16))],1);
    }
    else {
      digitalWrite(column[i%16],1);
      digitalWrite(layer[int(floor(i/16))],0);
    }
    delayMicroseconds(156); 
   }
  }
}

//xxxxxxxxxxxxxxxxxxxxFUNCTION LOOPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

int dir;
int b = 63;
void loop(){
  dir = returnDir();
  if(b<63){
    test[b+1]=0;
  }
  test[b]=1;
  Light(test,10); 
  Light(test,100);
  if(dir == 1){
    b=b-1;  
  }
}