LED Cube – a super cool way of torturing yourself

By on 1-20-2012 in Experiments

LED Cube – a super cool way of torturing yourself

Now, I have been trying to figure out a good way of passing my free time for a while. And everything I considered was just too difficult or too boring. Until now! I finally came across the LED Cube videos on youtube and said to myself – “Well, well, well, now this looks promising.” Torture yourself by trying to solder 64 LEDs into a cube, and then have fun making the LEDs jazz it up with some cool programming. Now, that is a super cool way of torturing yourself and passing your free time.

 

Now, sure I wanted to make it as painful as it could, but there has to be a method to the madness. So, I put up the whiteboard and laid down the basic plan. LED Cube with 4 rows, 4 columns and 4 planes – that makes it a LED cube with 64 LEDs. Super-bright Blue LEDs should make it look cool. Now, what do I need to run these LEDs, and I see the Arduino board jumping incessantly, chanting “me, me, me”. Sigh! So Arduino it is. But, the Arduino D only has 14 digital I/O pins and we need 20 I/O lines to control the 16 LED columns and 4 LED planes. So it was a good time to pull out the books on multiplexing. A few minutes later, I had decided to use the CD4514 decoder which provided me with 16 I/O lines controlled by just 4 digital I/O pins on the arduino! I chose to control the planes directly using 4 more I/O pins, and two other lines to control the decoder STROBE and INHIBIT signals.

 

Now, that I had the basic circuit finalized, it was time to draw up the diagrams:

Diagrams

Here is the first cube with the normal 3mm green LEDs which didn’t quite turn out well:

And here is the new LED cube with the super-bright blue LEDs (only one plane):

 

Second time around, I got hang of the trick to make a good looking cube. Once the cube was ready, it was time to make the shield for the decoder. And here is how it turned out:

 

With the shield ready and the LED cube soldered onto the prototyping pcb, the torture was finally over. Now, it was time to do some cool things with the cube. The code for controlling the cube is written in the Arduino IDE and requires a USB connection to burn the code into the arduino.

LEDCube Source

/*
LED Cube using a 4-16 Decoder
*/

/*4514 control pins*/
int STROBE = 2;
int INHIBIT = 7;

/*4514 input pins*/
int D0 = 3;
int D1 = 4;
int D2 = 5;
int D3 = 6;

/*Plane select pins*/
int PLANE_1 = 10;
int PLANE_2 = 11;
int PLANE_3 = 12;
int PLANE_4 = 13;

//previous z value
int prevZ = 0;

//flag
boolean flag = true;

long previousMillis = 0; // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {

Serial.begin(9600);
pinMode(PLANE_1,OUTPUT);
pinMode(PLANE_2,OUTPUT);
pinMode(PLANE_3,OUTPUT);
pinMode(PLANE_4,OUTPUT);
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(STROBE,OUTPUT);
pinMode(INHIBIT,OUTPUT);

//always select the decoder
digitalWrite(INHIBIT,0);

digitalWrite(PLANE_1,1);
digitalWrite(PLANE_2,1);
digitalWrite(PLANE_3,1);
digitalWrite(PLANE_4,1);

}

void loop() {
for(int plane = 3;plane >= 0; plane–){
for(int row = 1; row < 3;row++) {
for(int col = 1; col < 3;col++) {

digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);

delay(20);
}
}
delay(50);
}

for(int plane = 0;plane < 4; plane++){
int row = 0;
for(int col = 0; col < 4; col++) {
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(50);
}
for(row = 1; row < 3;row++) {
int col = 3;
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(25);
}
row = 3;
for(int col = 3; col >= 0; col–) {
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(50);
}
for(row = 2; row > 0;row–) {
int col = 0;
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(25);
}
delay(10);
}

for(int plane = 3;plane >= 0; plane–){
for(int row = 1; row < 3;row++) {
for(int col = 1; col < 3;col++) {

digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);

delay(20);
}
}
delay(50);
}

for(int plane = 0;plane < 4; plane++){
int row = 0;
for(int col = 0; col < 4; col++) {
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(5);
}
for(row = 1; row < 3;row++) {
int col = 3;
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(5);
}
row = 3;
for(int col = 3; col >= 0; col–) {
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(5);
}
for(row = 2; row > 0;row–) {
int col = 0;
digitalWrite(STROBE,1);
selectLED(row,col,plane);
digitalWrite(STROBE,0);
delay(5);
}
delay(50);
}

}

void selectLED(int x, int y, int z) {

digitalWrite(D3,x/2);
digitalWrite(D2,x%2);
digitalWrite(D1,y/2);
digitalWrite(D0,y%2);

for(int plane = 0; plane < 4; plane++) {
if(plane == z) {
digitalWrite(10+plane,0);
}
else {
digitalWrite(10+plane,1);
}
}

}

Next stop: getting the shield and the LED pcb refined to stack neatly on top of the arduino. I have managed to get the layouts ready, but finding a pcb fabricator who will take small orders is proving to be much more painful than making the cube. Here are the designs:

PCB Designs

{Update 1/4/2012}

Finally, I managed to complete the LED cube and here are the pictures: