 // to the physical connection of your LED cube to your
 // Arduino pins.
 
-#include Math.h
+//#include "font.h"
+#include <math.h>
 
 const int layer[4] = {
   A0,A1,A2,A3};
 const int column[16]={
   0,1,2,3,4,5,6,7,8,9,10,11,12,13,A4,A5};
-const int DELAY = 5; //Delay between cube layer alternations, in milliseconds. 
+const int DELAY = 5; // Delay for multiplexing
 int cube[4][4][4];
+int tmp[4][4][4];
+
+// number of LEDs on front and top combined is 7x4
+const int charHeight = 7;
+const int charWidth = 4;
+
+// 7x4 font
+const byte font[][4] = {
+        0x00, 0x00, 0x00, 0x00,         // Space
+        0x5f, 0x00, 0x00, 0x00,         // !
+        0x03, 0x00, 0x03, 0x00,         // "
+        0x28, 0x7c, 0x28, 0x00,         // #
+        0x2e, 0x6b, 0x3a, 0x00,         // $
+        0x48, 0x20, 0x10, 0x48,         // %
+        0x36, 0x49, 0x26, 0x50,         // &
+        0x03, 0x00, 0x00, 0x00,         // '
+
+        0x1c, 0x22, 0x41, 0x00,         // (
+        0x41, 0x22, 0x1c, 0x00,         // )
+        0x0a, 0x04, 0x0a, 0x00,         // *
+        0x04, 0x0e, 0x04, 0x00,         // +
+        0x60, 0x00, 0x00, 0x00,         // ,
+        0x04, 0x04, 0x04, 0x00,         // -
+        0x40, 0x00, 0x00, 0x00,         // .
+        0x60, 0x18, 0x06, 0x00,         // /
+
+        0x7f, 0x41, 0x7f, 0x00,         // 0
+        0x42, 0x7f, 0x40, 0x00,         // 1
+        0x7d, 0x45, 0x47, 0x00,         // 2
+        0x45, 0x45, 0x7f, 0x00,         // 3
+        0x3f, 0x20, 0x7f, 0x00,         // 4
+        0x47, 0x45, 0x7d, 0x00,         // 5
+        0x7f, 0x45, 0x7d, 0x00,         // 6
+        0x01, 0x01, 0x7f, 0x00,         // 7
+
+        0x7f, 0x45, 0x7f, 0x00,         // 8
+        0x5f, 0x51, 0x7f, 0x00,         // 9
+        0x50, 0x00, 0x00, 0x00,         // :
+        0x68, 0x00, 0x00, 0x00,         // ;
+        0x08, 0x14, 0x22, 0x00,         // <
+        0x14, 0x14, 0x14, 0x00,         // =
+        0x22, 0x14, 0x08, 0x00,         // >
+        0x59, 0x0f, 0x00, 0x00,         // ?
+
+        0x7a, 0x5a, 0x42, 0x7e,         // @
+        0x7f, 0x21, 0x7f, 0x00,         // A
+        0x7f, 0x45, 0x47, 0x7c,         // B
+        0x7f, 0x41, 0x63, 0x00,         // C
+        0x7f, 0x41, 0x41, 0x3e,         // D
+        0x7f, 0x45, 0x45, 0x00,         // E
+        0x7f, 0x05, 0x05, 0x00,         // F
+        0x7f, 0x41, 0x7d, 0x00,         // G
+        0x7f, 0x04, 0x7f, 0x00,         // H
+        0x41, 0x7f, 0x41, 0x00,         // I
+        0x40, 0x41, 0x7f, 0x01,         // J
+        0x7f, 0x04, 0x0a, 0x71,         // K
+        0x7f, 0x40, 0x40, 0x00,         // L
+        0x7f, 0x01, 0x07, 0x7c,         // M
+        0x7f, 0x01, 0x7f, 0x00,         // N
+        0x7f, 0x41, 0x7f, 0x00,         // O
+
+        0x7f, 0x21, 0x3f, 0x00,         // P
+        0x7f, 0x41, 0x21, 0x5f,         // Q
+        0x7f, 0x09, 0x79, 0x4f,         // R
+        0x47, 0x45, 0x7d, 0x00,         // S
+        0x01, 0x7f, 0x01, 0x00,         // T
+        0x7F, 0x40, 0x7f, 0x00,         // U
+        0x7f, 0x20, 0x10, 0x0f,         // V
+        0x7f, 0x40, 0x70, 0x1f,         // W
+        0x7b, 0x0e, 0x7b, 0x00,         // X
+        0x07, 0x7c, 0x07, 0x00,         // Y
+        0x79, 0x45, 0x43, 0x00,         // Z
+        0x7f, 0x41, 0x00, 0x00,         // [
+        0x06, 0x18, 0x60, 0x00,         // "\"
+        0x41, 0x7f, 0x00, 0x00,         // ]
+        0x02, 0x01, 0x02, 0x00,         // ^
+        0x40, 0x40, 0x40, 0x00,         // _
+
+        0x01, 0x02, 0x00, 0x00,         // `
+        0x74, 0x54, 0x7c, 0x00,         // a
+        0x7f, 0x44, 0x7c, 0x00,         // b
+        0x7c, 0x44, 0x44, 0x00,         // c
+        0x7c, 0x44, 0x7f, 0x00,         // d
+        0x7c, 0x54, 0x5c, 0x00,         // e
+        0x04, 0x7f, 0x05, 0x00,         // f
+        0x5c, 0x54, 0x7c, 0x00,         // g
+        0x7f, 0x04, 0x7c, 0x00,         // h
+        0x7d, 0x00, 0x00, 0x00,         // i
+        0x40, 0x7d, 0x00, 0x00,     // j
+        0x7f, 0x10, 0x6c, 0x00,         // k
+        0x7f, 0x40, 0x00, 0x00,         // l
+
+        0x7c, 0x04, 0x1c, 0x70,         // m
+        0x7c, 0x04, 0x7c, 0x00,         // n
+        0x7c, 0x44, 0x7c, 0x00,         // o
+        0x7c, 0x24, 0x3c, 0x00,         // p
+        0x3c, 0x24, 0x7c, 0x00,         // q
+        0x7c, 0x04, 0x04, 0x00,         // r
+        0x5c, 0x54, 0x74, 0x00,         // s
+        0x04, 0x7e, 0x44, 0x00,         // t
+        0x7c, 0x40, 0x7c, 0x00,         // u
+        0x7c, 0x20, 0x1c, 0x00,         // v
+        0x7c, 0x40, 0x70, 0x1c,         // w
+        0x6c, 0x10, 0x6c, 0x00,         // x
+        0x5c, 0x50, 0x7c, 0x00,         // y
+        0x64, 0x54, 0x4c, 0x00,         // z
+
+        0x08, 0x7f, 0x41, 0x00,         // {
+        0x7f, 0x00, 0x00, 0x00,         // |
+        0x41, 0x7f, 0x08, 0x00,         // }
+        0x01, 0x03, 0x02, 0x00,         // ~
+        0x7f, 0x7f, 0x7f, 0x00         // Full Filled
+};
+
 
 //Setup
 void setup(){

  clearCube();
}

void patternThrowDice(){
print(random(6));
}


void rotate(int x, int y, int z, double theta){
int tmp[4][4][4];

for (int i; i<3; i++)
for (int j=0; j<3; j++)
for (int k=0;k<3;k++){
if (l>=0 && l<4 && m>=0 && k <4){
tmp[i][j][k]=cube[i][j][k];
}}
// rotate around the z axis
 
int l = (int) i*Math.Cos(theta) - j* Math.Sin(theta);
int m = (int) i*Math.Sin(theta) + j*Math.Cos(theta);

}

void loop(){
  patternKnightRider(5);
  pattenThrowDice();
  fillCube();
  render(1000);
  clearCube();

  patternBlinkCube(30);
  patternRotateClockwise(20);
  patternRandomLED(20);
}

void print(char ch)
{
  byte b;
  // make sure the character is within the alphabet bounds (defined by the font.h file)
  // if it's not, make it a blank character
  if (ch < 32 || ch > 126)
    ch = 32;
  // converts the ASCII number to the font index number
  ch -= 32;
  // step through each byte of the character array
  for (int i=0; i<charWidth; i++) {
    b = font[ch][i];
    // bit shift through the byte and output it to the pin
    for (int k=0; k<4; k++) 
     cube[i][0][k] =  !!(b & (1 << k));
    for (int j=1; j<4; j++)
     cube[i][j][3] = !!(b & (1 << (3+j)));
  }
}


void patternThrowDice(){
  //print(random(6));
}


void rotate(double theta){
  for (int i; i<3; i++)
    for (int j=0; j<3; j++)
      for (int k=0;k<3;k++){
        int l = (int) (0.5 +i*cos(theta) - j*sin(theta));
        int m = (int) (0.5 +i*sin(theta) + j*cos(theta));
        if (l>=0 && l<4 && m>=0 && k <4){
          tmp[l][m][k]=cube[i][j][k];
          // rotate around the z axis
        }
      }
  for (int i=0; i<3; i++)
    for (int j=0; j<3; j++)
      for (int k=0; k<3; k++){
        cube[i][j][k]=tmp[i][j][k];
      }
}

void patternBlinkIn(){
