Step 4: Using the Software

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.

The code is also available on Github at gzip/arduino-ledcube.

Thanks for reading!

 
Remove these adsRemove these ads by Signing Up
lynxhockey says: Apr 19, 2013. 3:33 PM
Hey, this is my first Arduino project, but I'm having some issues getting the code pushed from the sketch to the Arduino. (I'm running 1.0.4 if that matters.) However, I keep getting an error when I try to upload it that says "avrdude: stk500_getsync(): not in sync: resp=0x00" . Also, in the event that it matters, I'm using the Arduino Diecimila.
gzip (author) in reply to lynxhockeyApr 20, 2013. 9:59 AM
You might have the wrong programmer selected or maybe it's not getting enough power.
herroc says: Apr 6, 2013. 6:44 PM
awesome project, took about 2hrs start to finish. No issues at all, though i would bend the legs the opposite way (as suggested). thanks
jtmanders says: Jul 17, 2012. 6:43 PM
ok so i have built my cube very similar to yours and the code works on it. however my cube is 4x4....how would i go about changing the code so it would run the entire cube? is this even possible? thanks
gzip (author) in reply to jtmandersJul 27, 2012. 12:20 AM
This is a work in progress so let me know if you have any luck with it.
Arduino LED Cube code
ride on toy dude says: Jul 20, 2012. 1:25 PM
Thanks for the code!!
4eyes12 says: Apr 25, 2012. 10:46 PM
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??
mastercheefryu says: Feb 22, 2012. 9:57 PM
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
Cloudhail in reply to mastercheefryuMar 7, 2012. 11:04 PM
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?
gzip (author) in reply to CloudhailMar 8, 2012. 7:33 PM
You don't need to unzip to the examples folder separately since the examples under libraries will get picked up automatically. Sketch > Import Library > LedCube is only needed for a brand new sketch. That will add #include <LedCube.h> to the top of the sketch.
Cloudhail in reply to gzipMar 8, 2012. 8:29 PM
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.
gzip (author) in reply to CloudhailMar 8, 2012. 9:49 PM
So even with the included example you need to import library before it compiles correctly?
Cloudhail in reply to gzipMar 8, 2012. 10:07 PM
Yes
gzip (author) in reply to CloudhailMar 8, 2012. 11:26 PM
That's strange. I wonder what's going on there. Is the #include missing to begin with and then the import adds it? I tried downloading the zip and extracting it fresh but couldn't reproduce. I unzipped to libraries in my sketchbook and then to the main libraries folder. Both worked. What version of the Arduino software are you using and on what OS?
Cloudhail in reply to gzipMar 9, 2012. 12:46 AM
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.
gzip (author) in reply to CloudhailMar 9, 2012. 6:29 PM
And you're using the Arduino 1.0 software or older? I'm on Linux (Ubuntu) with 1.0 so I'll try Windows as well (but all I have is XP). You shouldn't have to import the lib for the included example but maybe some combination of software is causing problems.
stewart_14 in reply to mastercheefryuMar 4, 2012. 9:20 PM
Did you ever get this fixed? im having the same problem!
gzip (author) in reply to mastercheefryuFeb 22, 2012. 11:19 PM
The sketchbook folder should be created automatically under your home directory when you open the arduino software. The exact location will vary according to OS. You can create the libraries folder there if it's not already present.

Another option is to add the library to the main libraries folder (which is in the same folder as the arduino executable). It's just a less flexible location since you'll have to move any libraries that you've added there the next time you upgrade the arduino software.

Either way you should find the example under File > Examples > LedCube > ledcube if you've set everything up correctly.
stewart_14 in reply to gzipMar 4, 2012. 9:31 PM
Did you ever get this fixed? im having the same problem!
alsetalokin says: Feb 27, 2012. 6:53 AM
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.
alsetalokin says: Feb 26, 2012. 5:53 PM
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

alsetalokin says: Feb 25, 2012. 10:33 AM
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 !!??
Blackice504 says: Jul 26, 2011. 8:06 AM
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.
gzip (author) in reply to Blackice504Feb 22, 2012. 11:28 PM
Late answer but the reason is that the current will vary depending on how many LEDs are lit on any given level. The only reliable method of limiting current is to limit it for each individual LED since any number of them can be lit at any given time.
gzip (author) says: Dec 7, 2011. 10:33 PM
The software is now updated for Arduino 1.0 and includes an example in the download.
birthur in reply to gzipFeb 6, 2012. 5:00 PM
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
gzip (author) in reply to birthurFeb 8, 2012. 12:01 AM
What's the error?
birthur in reply to gzipFeb 11, 2012. 8:54 AM
For example:´ LedCube does not name a type´
I am also new to this and do not speak English XD
birthur in reply to gzipFeb 10, 2012. 1:51 PM
-
4.jpg
birthur in reply to gzipFeb 10, 2012. 1:44 PM
I suggest you open the code and you check
3.jpg1.jpg2.jpg
gzip (author) in reply to birthurFeb 11, 2012. 9:54 AM
I'm not sure what you're doing with the "aaqqq" file is but it looks like a version of LedCube.h with truncated lines. The truncated lines are creating syntax errors.

As for "LedCube does not name a type" and "LedCube.h: No such file or directory", It sounds like you still need to unzip the LedCube folder to sketchbook/libraries. Once you have that set up correctly you'll get an entry under File > Examples > LedCube > ledcube which you can open and compile without problems.
birthur in reply to gzipFeb 13, 2012. 5:49 PM
oka....! thanks. I proves to see what happens
jlateur in reply to gzipDec 8, 2011. 11:01 AM
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
birthur says: Feb 6, 2012. 4:57 PM
hello, do not know why but this code gives me error in the arduino 1.0. Could you please help me?
lostalaska says: Jun 28, 2011. 1:49 AM
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!
mertaxoy says: Nov 14, 2010. 9:47 AM
hii can i use this lib with other programm on a atmega16 ?
Simpson_jr in reply to mertaxoyJun 12, 2011. 1:53 PM
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.
josiahritchie says: Aug 31, 2010. 8:10 PM
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.
gzip (author) in reply to josiahritchieSep 1, 2010. 7:29 PM
The code was written with larger cubes in mind but it'd be a bit lucky if it worked out of the box. Even so, user adumas reported in the comments below that he had it working with a 4x4x4. Post back if you get anywhere with that,
achollowell says: Dec 8, 2009. 7:32 PM
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

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!