Introduction: How to Write Your Own 4x4x4 LED Cube Show for Arduino

About: “To invent, you need a good imagination and a pile of junk.” ― Thomas A. Edison

There are Many Instructables out there teaching you how to build an LED cube, however only a few actually help you write the code to go with it but rather just give you some to use, thus stopping your creative potential! Also there are many different ways to program the cube, but this is one of the simpler ways I found so far. If you don't know where to start, start here!

This instructable will be an "addition" onto my previous one on how to make the LED cube itself. It can be found HERE.
For those of you that built my cube, consider this the last few steps.

This instructable assumes you either know how a LED cube works or have built one yourself.

Also I assume that you have built a 4x4x4 cube (because that is what I have to take pictures of). However, this will work with any cube if wired properly.

Note that the code and cube run on Arduino.

Also, I lay no clam to the code found in this instructable, I have simply altered an existing code that has been floating around the internet. My hope here is to further explain this code in a way that people which have no prior knowledge of coding can form and write their own shows. If you are or know who originally wrote this code feel free to contact me!

Things Needed:

  • An LED Cube
  • An Arduino mega or uno, according to cube size
  • Arduino IDE
  • Computer
  • A fair amount of patience and time


Video of new pattern I wrote(Show 2):

UPDATE:

Since the 4x4x4 cube I have built a 8x8x8 LED cube and interfaced it with an old IPod Nano to play music. The animations on the cube were simply programmed and timed correctly to correspond to the music.

Step 1: Setting Up Cube

For the main construction of the cube refer to my other instructable here.

However, we are going to change some things with the setup.

First off the transistors i used are not needed for these types of codes. Don't cut them, but just tuck the wires to the side and ignore them. They are still needed for some other codes.

In this setup run wires directly from the ground layers directly into Arduino. Notice in Photo one i just tapped into the ground solder lines that go to the transistor board. (Red trails are solder on other side)

Then the wire go directly into the arduino where the transistor board used to connect. (Photo 2)
I color coded them for easy connections.

The 16 Columns are all wired the same as they were before. 

NOTE:
Find the part in the code that looks like this:

int LEDPin[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 14, 15};
int PlanePin[] = {16, 17, 18, 19};

The order the pins are listed changes the order they are in the code, so change this to fit your needs.



Once you have your cube set up properly move on to the next step. 


Step 2: Download the Codes

Extract the files and read the READ ME.

And if you don't have Arduino IDE, Download it.

Step 3: Understanding How the Code Works

Before writing the code you must first have a full understanding of how it works.

This entire program is based off of one line of text:

B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
     1         2          3        4          5         6        7          8          9         10        11       12       13       14       15       16

The 16 B0000 sets all represent a row of LEDs in the cube.
(The number under is the row number in relation to the code) refer to photo 2
Now don't confuse rows and columns. Rows are horizontal, columns are vertical.
Look at Photo 1



And the 10 at the end is the speed at which that frame is played.

Think of each line of code being a frame in a movie, if you slow it down there are individual pictures, but when sped up, its an animation.

Now lets break it down even further:
Each 0 is an LED, 1 is on, 0 is off.
For instance: B0000 is a entire row turned off, B1111 is an entire row turned on.

Now even further, you want to turn on an individual LED.
refer to Photo 3, it will be your best friend while doing this, write it down yourself. 
When looking at a row from the front, the first LED is the last 0 in B0000 
go look at Photo 3....pictures explain better than words.

For example, you want to turn on the bottom left hand corner LED on and everything else off.
it would look like this:
B0001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,


Play with this yourself, the more you experience it, the faster and easier you can program.







Step 4: Writing Your Own Show!

First off open open LED_1cube_4x4x4_Show_2 to make sure your cube is wired correctly. It should look like the video in the beginning.

Once verifying that, take a look at the code and how it is put together.
The only part that matters is the B0000 stuff. Everything else just don't touch.(with the exception of changing pin #)

Lets Write your first show!
Open LED_1cube_4x4x4_Blank_Show_
This is the show, but blank! 

There is one frame there to get you started and row numbers across the top.
To turn a LED on just replace some zeros with some ones! not much too it!
Copy and paste this over and over again and your set!
B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

One last thing. 
Near the top you can find this:
#define TIMECONST 20
You can change the 20 to whatever number you want (its the time to view each frame in milliseconds).

Use this as a programming tool, slow it down a lot to look at individual frames to make sure everything is right or to figure out what is wrong. 




Step 5: Examples

All take place when looking from front.

Turn on bottom left hand light:
Photo 1
B0001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

Turn on row 1:
Photo 2
B1111,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

Turn on all four corners: 
Photo 3
B1001,B0000,B0000,B1001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B1001,B0000,B0000,B1001,10

Turn on all of layer 1:
Photo 4
B1111,B1111,B1111,B11111,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

Step 6: Finishing Up

Hope this helps someone!
Took me a while to figure out how to do this, hopefully save everyone some time and headache.
Feel free to comment or message me!
Thanks for reading.

Arduino Contest

Participated in the
Arduino Contest