3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

LED Cube and Arduino Lib

Step 4Using the Software

Using the Software
«
  • cube-solder-diagram.png
  • cubelib.png
I found a few code examples floating around the 'net for controlling an LED cube. They all required large arrays of binary or hex data to control the LEDs. I figured there must be an easier way so I set out to write my own software.

My first decision was to make the software mirror the hardware. That meant addressing each LED by column and level instead of using raw port data or the traditional x, y, z. The second decision was to start with basic functions, like turning a single light on or off, and building up from there.

Lastly I decided to introduce two features which are useful for more interesting effects. One is a buffer which allows the basic functions to build up more complex patterns. The other is a sequence function which lights an array of LEDs one at a time, or all at once.

The library started as procedural code and loose functions. From there it was very easy to follow the tutorial to create a reusable Arduino library.

Be sure to download the library and unzip it to sketchbook/libraries. If set up correctly you should find an example in the Arduino software under File > Examples > LedCube > ledcube.

Thanks for reading!

« Previous StepDownload PDFView All StepsNext Step »
28 comments
Apr 25, 2012. 10:46 PM4eyes12 says:
Made the cube and uploaded the script, but I'm having a technical issue. My bottom center led in the cube will not function in the arduino routine, but is perfectly functional when tested with a battery... dose not seem to be a connection problem as the two leds above it still function. Any advice or ideas??
Feb 22, 2012. 9:57 PMmastercheefryu says:
Im getting some problems, the arduino 1.0 version doesnt have the sketch folder so where should i place it? directly to libraries? Im doing that but its not working. These are the probs im getting:

ledcube.cpp:1:21: error: LedCube.h: No such file or directory
ledcube.pde:-1: error: 'LedCube' does not name a type
ledcube.cpp: In function 'void loop()':
ledcube.pde:-1: error: 'cube' was not declared in this scope

Plz help me
Mar 7, 2012. 11:04 PMCloudhail says:
I unzipped it to the library folder then i unzipped it to the examples folder. in the actual arduino script editor you have to go to the sketch tab (up top) and IMPORT LIBRARY!!! select ledcube. once that is imported I went to the file tab(uptop) and loaded ledcube. with all of that done I hit upload and It works now. Does this make any sense?
Mar 8, 2012. 8:29 PMCloudhail says:
This is correct, sorry for the extra step. However the import library is a must. This will give you the error if you don't load the library. It took me a little bit to figure that out.
Mar 8, 2012. 10:07 PMCloudhail says:
Yes
Mar 9, 2012. 12:46 AMCloudhail says:
Sadly I'm still on vista (I'm a Mac) I'm using the UNO, and yes it does put the #include tag into the top of the script. It's working for me just fine. But this is the way I got it to work. I just figure if anyone was having the same problem as me I could share. Is this not supposed to happen? It may help to know that I start the editor program up without anything loaded at all. (just double click the arduino symbol icon) then I do what I mentioned before.
Mar 4, 2012. 9:20 PMstewart_14 says:
Did you ever get this fixed? im having the same problem!
Mar 4, 2012. 9:31 PMstewart_14 says:
Did you ever get this fixed? im having the same problem!
Feb 27, 2012. 6:53 AMalsetalokin says:
I put a video of my 4x4x4 cube on YT, with a link back here. Thanks again, gzip and bogyman57 for the instructable and the code package!!

http://www.youtube.com/watch?v=VH2tW6YQ-5U

I thought this instructable was the best of many concerning the building and operation of an Arduino-powered LED cube, even though it was just for 3x3x3. The 4x4x4 version is still pretty cheap and simple to build, but the other builders didn't have the great program code that gzip and bogyman57 have here. The existing code is "almost" fully ready for 4x4x4, and it's obvious that gzip and bogy wrote it with as much generality in mind as possible. I tried to make my modifications and additions with the same idea, but there are a couple places where I got lazy and hard-coded the 4 and 16 parameters or a brute-force routine. This can be easily fixed, I think, to generalize the sketch and the other files to arbitrary X x Y x Z arrays.
Feb 26, 2012. 5:53 PMalsetalokin says:
OK... after a couple days work I fixed the software library to cover the 4x4x4 cube, with some fixes to the patterns (not all) and a button to select pattern and a couple of basic sound effects.
My cube works great with the OSEPP arduino MEGA clone. Others might have to adjust the pinout arrays in the .pde file to correspond to your cube wiring, but if you follow the instructions in this instructable and just extend in the logical manner your pinout will be the same as mine, probably.

Thanks for this great instructable and the originals of the library files!! I can really appreciate how much work went into writing those files.

Others may also need to adjust the timing variables to get the patterns to display pleasantly on your board.

The zip file of the .pde, the .cpp, and the .h files is here:

[url]http://205.196.121.50/3jbuw3i36mvg/laj2cixxb9z99hh/AlsLEDCube4x4x4Button.zip[/url]

Fun Stuff !!
--Alsetalokin

Feb 25, 2012. 10:33 AMalsetalokin says:
The "OneLevelAtATime1" pattern function only lit the bottom 2 levels of my 3x3x3 corner (of my 4x4x4 cube) but all other patterns worked. The "lightLevels" function in LEDCube.cpp tests for r=TRUE but the call from the .pde file passes r=0 for the initial level.... which of course is r=FALSE so that level doesn't light up.
My solution was to replace the
" if (r && r < levels) "
with the code
" if ((r+1) && r < levels) "
in the "lightLevels" function in the LEDCube.cpp file, save the file, exit the Arduino IDE and restart, recompile your .pde file. Now all three levels work in the "OneLevelAtATime1" function call.

Please -- can you help to extend your code to a 4x4x4 cube !!??
Jul 26, 2011. 8:06 AMBlackice504 says:
Hi mate nice job, but if all the transitors are connecting the levels or rows to ground why not use just 3 transistors or even having said that do the calculations for the total current and have 1 resistor to ground on the trasistor because no matter what all current must flow to ground via the transistor?
yes the value would be higher then what you are using i.e 1 watt but i think that may work but i could be wrong anyway i have nearly finished my own so i will try this with a 50 Ohm POT, anyway thanks for your help.
Feb 6, 2012. 5:00 PMbirthur says:
hello, do not know why but this code gives me error in the arduino 1.0. Could you please help me and if you leave me a comment here would be great since I have a Blast Card with which to pay to download the file
Feb 11, 2012. 8:54 AMbirthur says:
For example:´ LedCube does not name a type´
I am also new to this and do not speak English XD
Feb 10, 2012. 1:51 PMbirthur says:
-
Feb 10, 2012. 1:44 PMbirthur says:
I suggest you open the code and you check
Feb 13, 2012. 5:49 PMbirthur says:
oka....! thanks. I proves to see what happens
Dec 8, 2011. 11:01 AMjlateur says:
I want to make a animation as firework for the time of the year. But i don't understand the whole script. can you help me on way? like how do i set 1 led to high etc
Feb 6, 2012. 4:57 PMbirthur says:
hello, do not know why but this code gives me error in the arduino 1.0. Could you please help me?
Jun 28, 2011. 1:49 AMlostalaska says:
Thanks for the guide, followed it all and eventually got it all working. This was my first electronics project I've tried, so I wired the NPN transistors incorrectly initially and totally missed placing the library in the "library" folder. I just had to read through the guide a couple times, not any fault to your guide. Just me being a noob.

I'm playing around with the code now and I see the basic theory of how it works and now that's it all together and I'm able to tweak the code. Gonna try a 4x4x4 using 16 gauge wire to build a grid then bend the LED legs so the slide on for easier soldering and hopefully to make the thing a little more structurally solid. I saw some pictures in another LED cube guide in the comments that explained it and had pictures. My 3x3x3 cube I used a jig, but soldering the levels together I bent a few out of square so they don't all line up perfectly.  Still this was totally awesome and thanks!
Nov 14, 2010. 9:47 AMmertaxoy says:
hii can i use this lib with other programm on a atmega16 ?
Jun 12, 2011. 1:53 PMSimpson_jr says:
You may have to adapt the code depending on the IDE used, but... you could also try to find an Arduino bootloader for the atmega16 and run the Arduino IDE.
Aug 31, 2010. 8:10 PMjosiahritchie says:
Can this class address larger cubes than a 3x3x3? It looks like the code was built with that in mind, but has it been tested by anyone? I've been thinking about a 4 or 5 LED cube, but so far I guess I'd need a shift register and I figure the Library would have to be aware of the shift register. I don't know enough about it to know if it just simply is or if that requires special attention.
Dec 8, 2009. 7:32 PMachollowell says:
Man this is cool just got my first Arduino still learning but going to build one soon

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
41
Followers
5
Author:gzip