Top Banner

of 10

3X3 LED Cube Programming Tips (Arduino Based)

Oct 30, 2015

Download

Documents

Syed Hameed

3X3 LED Cube
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • How to make that cube do what you want it to!

    I followed the instructable here (http://www.instructables.com/id/LED-Cube-and-Arduino-Lib/?

    ALLSTEPS)and built a 3x3 LED cube run by an Arduino. I was delighted! But it could only do one

    routine. Again and again and again and again and again.... So I decided to try and program a different

    routine. I needed a change. Do you?

    If you study the code in the cube's Arduino sketch you can see all the instructions right in front of you.

    To me, it looks like the Matrix, streaming by in all its digital confusability. I needed a graphic interface to

    help me code the routines. I FOUND ONE!!! But it wrote code that contained extra information that I did

    not want. How to rewrite all those instructions? Read on!

    Be prepared, this is a twisted solution, combining an (apparently) anonymous website with a macro in

    my word processor, but in the end I have come up with a routine that is very powerful indeed!

    Step 1: Graphic pattern generator

    (/files/deriv/FYF/A071/GZKGLWXS/FYFA071GZKGLWXS.LARGE.jpg)

    About This Instructable

    Posted:Mar 11, 2012

    License:

    9,244 views

    17 favorites

    (/member/stringstretcher/)

    stringstretcher

    (/member/stringstretcher/)

    video channel(http://www.youtube.com/user/shortyumpire?ob=0&feature=results_main)

    Follow

    former musician. I have made kites,music instruments, electronic doodads,pitching machines, stomp rockets, waterrockets, windless windchimes, circuit benttoys, animatronics, clock escapements,CNC...read more (/member/stringstretcher/)

    4

    Bio:

    (/id/Simple-Deluxe-Sonotube-Food-Dehydrator)

    More by stringstretcher

    (/)

    let's make

    share what you make >

    (/about/submit.jsp)

    (/)

    Explore (/tag/type-id/) Create (/about/submit.jsp) Contests (/contest/) Community (/community/) Login (/you/)

  • I searched and searched for "LED Cube Programmers" on the web. I found some, but they were for

    PIC based cubes. I changed the title of my search to "LED Cube Pattern Generator" and BINGO! I

    finally found this one (http://mezdata.de/avr/stocka-LEDCube-Pattern-Tool-40fdc8a/), and it allowed

    my simple mind to grasp the relationship between little flashing lights and gobs of 1's and 0's. I could

    punch little buttons on the screen and see a simulation of what I was doing! Just what I wanted. This

    generator allows one to use a cube of any size! Press the "new" button and you will be prompted to set

    up your cube.

    'Insert' creates a new frame, just like a simple animation program. We are going to make a 'flip book,'

    in effect. Each page is programmed and then you hit the insert button to add another frame. Notice the

    speed parameter near the bottom of the window marked 'frames.' F and E mean 'Fill' and 'Erase.'

    Program a few frames and hit the 'Play' button. Your animation will be shown in the 'preview' window.

    Simple! When you are done and want to save your new light show, hit the 'File' button. You will see the

    buttons marked 'New',' to Code',' Load' and 'Save' appear. Press 'To Code,' and a window will open,

    asking you to choose in which order you wish to display your data. You can go back and change this

    later if you get it wrong. Just choose one for now.

    You will then see a window with all your animation's coded bytes.

    Step 2: Clean up that code, please!

    Related

    See More (/tag/type-id/?q=)

    (http://cdn.instructables.com/F00/M1GW/GZMIUHSI/F00M1GWGZMIUHSI.LARGE.jpg)

    (/files/deriv/FM9/XLJ9/GZMIUJFP/FM9XLJ9GZMIUJFP.LARGE.jpg)

    (http://cdn.instructables.com/F90/NJ94/GZLW4A7B/F90NJ94GZLW4A7B.LARGE.jpg)

    LED (/tag/type-id/category-technology/keyw ord-

    led/)

    Cube (/tag/type-id/category-technology/keyw ord-

    cube/)

    Arduino (/tag/type-id/category-technology/keyw ord-

    arduino/)

    sequence (/tag/type-id/category-

    technology/keyw ord-sequence/)

    programming (/tag/type-id/category-

    technology/keyw ord-programming/)

    help (/tag/type-id/category-technology/keyw ord-

    help/)

    Tags:

    (/id/4x4x4-

    4x4x4 LED Cube Arduino(/id/4x4x4-LED-Cube-Arduino/)by jtmanders(/member/jtmanders/)

    (/id/The-

    The 4x4x4 LED cube(Arduino) (/id/The-4x4x4-LED-cube-Arduino/)by forte1994(/member/forte1994/)

    (/id/Arduino-

    Arduino 4x4x4 LED Cube(/id/Arduino-4x4x4-LED-Cube/)by Phogie7 (/member/Phogie7/)

    (/id/3-x-3-

    3 x 3 LED Cube with ArduinoUNO (/id/3-x-3-LED-Cube-with-Arduino-UNO/)by adrian_orozco(/member/adrian_orozco/)

    (/id/3x3x3-

    3x3x3 LED Cube (/id/3x3x3-LED-Cube-1/)by BIGDOG1971(/member/BIGDOG1971/)

  • I select all the code in the window and copy. Ok, now here comes the fun part. Open your word

    processor and paste that code in a new document. I use Libre Office (http://www.libreoffice.org/), and

    have not tried this on other software. You may be able to improve on my crazy method, please share

    any tips!

    Step 3: Rewrite that mess a little bit.

    (http://cdn.instructables.com/FV9/JT28/GZMIUHSP/FV9JT28GZMIUHSP.LARGE.jpg)

    (http://cdn.instructables.com/FG7/3WQW/GZLW4A7N/FG73WQWGZLW4A7N.LARGE.jpg)

  • This is what the pattern generator gives me, and it has some extra information I do not want in my

    sketch, so we need to remove some characters and make it easier for us to use later. First, get rid of

    the first and last rows of information, all we want is everything in between those two rows. It should look

    like this:

    Step 4: The Solution!

    This is a very short example, so there are not many brackets, but if you program a longer animation

    (http://cdn.instructables.com/FP4/I459/GZKG341C/FP4I459GZKG341C.LARGE.jpg)

    (http://cdn.instructables.com/F1V/JBGR/GZKGLUDT/F1VJBGRGZKGLUDT.LARGE.jpg)

    (/files/deriv/F2V/81B5/GZLW4A8J/F2V81B5GZLW4A8J.LARGE.jpg)

  • removing all those brackets would take too much time. Being an inventor (always looking for a solution,

    probably due to laziness in my case) I set out to find a different way to accomplish that. The solution?

    MACRO! I did a search and found out why my "record macro" button was not active in LibreOffice:

    Here (http://en.libreofficeforum.org/node/137) is the answer to that question, follow the instructions and

    you can then record a macro. What this does is allow us to execute a series of edits once, record

    those actions as a single command and then perform the edit on the entire document quickly. I'll try

    and guide us through one example of an edit using my macro and LibreOffice.

    First I clicked on Record Macro (see pics)

    Next I selected all the text using ctrl A

    Then I used Find and Replace to edit out the characters in my program information.

    In the find and replace menu, enter the open bracket '{' at the beginning of the text lines like this:

    Search for {

    in the replace line, leave a blank. Click on 'replace all'. You will get a report of how many symbols were

    replaced.

    That's one! Now we repeat that sequence with the next symbol, the close bracket ' }' (no quote) and

    replace it also with a blank.

    Next symbol to replace is the '0' followed by lower case letter 'b' (0b) with an upper case 'B' instead.

    Have a look at the pictures in this step to see what my text is looking like.

    After this last Find and Replace step, we click on the button that says 'stop recording,' in order to make

    this editing function a macro. (see pictures here) You will be prompted to save the macro, try to

    remember what you call it!

    Now erase all the text and save the document as a blank slate for your routine. I called my document

    'blank slate' (duh.)

    Next time I want to program I can skip the steps to create a new macro, it should already be there for

    me to use. I can program short routines and save them as text files, then piece together the snippets

    into a longer routine at a later time.

    Step 5: Using the macro function to edit another animation

    Now we have programmed our word processor to edit the information generated by the pattern

    generator into a more friendly format that can be used in our sketch. Let's try the whole procedure so

    far:

    Generate a new animation, say three frames of blinks anywhere. Click on New and enter the number of

    diodes in your cube. Mine is 3,3,3.

    Next I will turn on all the lights in the first frame of our animation.

    Next step: add another frame with the 'insert' button. Turn off all but one light anywhere.

    Click 'insert' once more and add one more frame, all off.

    (/files/deriv/F0G/94VP/GZLW4A8L/F0G94VPGZLW4A8L.LARGE.jpg)

    (/files/deriv/FCY/N5U6/GZMIUHXU/FCYN5U6GZMIUHXU.LARGE.jpg)

  • Now we have a new sequence of three frames, time to generate the code.

    Click 'File' and then 'To Code' to see the code window.

    Select one of the options offered, I chose 'Depth, Height, Width' (you may have to experiment here)

    Select everything inside the code window and copy.

    Paste into our word processor document.

    Remove the first and last lines as we did earlier.

    Select all the text.

    Now we want to run that macro. Under 'tools/macro/run macro' we see a list to choose from. You will

    need to find your macro, probably at the last entry in the list, look around and see if you can find it.

    This part is difficult for me to describe. I felt that it should have been easier to find, but then I am new

    to macros. The macro should appear in the window on the right once you have found it.

    Click on it and hit run.

    That 'should' clean up the code in one step!

    Step 6: What do I do now?

    Now we have a programmed sequence of frames, and transformed the code to a format that will let us

    run it inside our Arduino sketch. 'What sketch' you ask? The Arduino sketch I use to drive my cube

    looks like this:

    /*

    Based on ledcube.c from Make: September 7, 2007 weekend podcast

    http://blog.makezine.com/archive/2007/09/make_a_pocket_led_cube_we.html

    Custom animation programmed by Mark Boszko, http://stationinthemetro.com

    */

    #include // allows use of PROGMEM to store patterns in flash

    #define CUBESIZE 3

    #define PLANESIZE CUBESIZE*CUBESIZE

    #define PLANETIME 3333 // time each plane is displayed in us -> 100 Hz refresh

    #define TIMECONST 5 // multiplies DisplayTime to get ms - why not =100?

    // LED Pattern Table in PROGMEM - last column is display time in 100ms units

    // TODO this could be a lot more compact but not with binary pattern representation

    prog_uchar PROGMEM PatternTable[] = {

    B101, B010, B101, B000, B000, B000, B000, B000, B000, 50 ,

    B000, B000, B000, B000, B010, B000, B000, B000, B000, 50 ,

    B000, B000, B000, B000, B000, B000, B101, B010, B101, 50 ,

    B000, B000, B000, B000, B010, B000, B000, B000, B000, 50 ,

    }

    /*

    ** Defining pins in array makes it easier to rearrange how cube is wired

    ** Adjust numbers here until LEDs flash in order - L to R, T to B

    ** Note that analog inputs 0-5 are also digital outputs 14-19!

    ** Pin DigitalOut0 (serial RX) and AnalogIn5 are left open for future apps

    */

    //int LEDPin[] = {16, 3, 1, 15, 4, 6, 14, 5, 7};

    int LEDPin[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10};

    //int PlanePin[] = {19, 18, 17};

    int PlanePin[] = {13, 12, 11};

    // initialization

    void setup()

    {

    int pin; // loop counter

  • // set up LED pins as output (active HIGH)

    for (pin=0; pin0 and current time < EndTime

    while ( millis() < EndTime ) {

    patbufidx = 0; // reset index counter to beginning of buffer

    // loop over planes

    for (plane=0; plane

  • Step 7: Modifying the sketch

    There a three things I changed in that sketch to make it run on my cube.

    1. The settings for HIGH and LOW level states

    2. The order of the output pins

    3. The data for the routine, which is what this is all really about!

    Let's look at this in detail. I have highlighted the words HIGH and LOW here. I reversed them from the

    original program. You may or may not have too. Experiment.

    // initialization

    void setup()

    {

    int pin; // loop counter

    // set up LED pins as output (active HIGH)

    for (pin=0; pin

  • Post Comment

    (/member/arjan901/)

    Jan 7, 2013. 3:38 AM Reply (CLJNQNMHAQ316Z5)

    2

    (/member/stringstretcher/)

    Jan 9, 2013. 2:17 AM Reply (C3847N3HBNXV1NJ)

    (/member/Eduort/)

    Nov 9, 2012. 9:37 PM Reply (C8JGG0NH994NE1E)

    2

    (/member/stringstretcher/)

    Nov 12, 2012. 12:13 PM Reply (CURP47VH994XOI1)

    (/member/Hanni43/)

    Nov 3, 2012. 10:29 AM Reply (CM67RLHH91LG0B7)

    All I can say is, hack it!

    Give it a try and share some of your own routines here!

    Enjoy.

    arjan901 (/member/arjan901/) says:

    i have a question about the code. When i want to upload it to my arduino, i get an error on line: int LEDPin[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10};

    it says: sketch_jan07a:34: error: expected ',' or ';' before 'int' sketch_jan07a.ino: In function 'void setup()': sketch_jan07a:45: error: 'LEDPin' was not declared in this scope sketch_jan07a.ino: In function 'void loop()': sketch_jan07a:95: error: 'LEDPin' was not declared in this scope

    what can be the problem?

    stringstretcher (/member/stringstretcher/) (author) says:

    Your first error indicates a problem*before* inserting the changed lines.Check everything VERY carefullyfrom the beginning and see if you canfind a missing semicolon.

    Eduort (/member/Eduort/) says:

    Hi, this is very interesting, but i have a question, is posible to program 2 or 3 routines and start themwhit a button? thanks for afterhand

    stringstretcher (/member/stringstretcher/) (author) says:

    I never thought of that... why not? Itis a matter of storing the routinesas data, and then using a switch toselect the data set, or the switchcould select the starting point of theroutine with case switchcommands. There are others outthere who are brazilians of timesbetter at this than I am. We willhave to seek the answer!!

    Hanni43 (/member/Hanni43/) says:

    Great able ,been looking for the led generator & everytime go to Download more junk seems to begetting downloaded than the program, where did you get it Wout all the other advertisers junk..Thanksfor sharing project & time finding the way to go..D

    stringstretcher (/member/stringstretcher/) (author) says:

  • 2(/member/stringstretcher/)

    Mar 11, 2012. 2:38 PM Reply (C3R01K0GZKGLX3J)

    I couldn't understand how to embed a video in any of the steps. Here is a link to one showing a shortroutine done using this method.

    http://www.youtube.com/watch?v=aUib24e1Dzk

    About Us

    Who We Are (/about/)

    Advertise (/advertise/)

    Contact (/about/contact.jsp)

    Jobs (/community?categoryGroup=marketplace&category=jobs_internships)

    Help (/community?categoryGroup=Help)

    Find Us

    Facebook (http://www.facebook.com/instructables)

    Youtube (http://www.youtube.com/user/instructablestv)

    Twitter (http://www.twitter.com/instructables)

    Pinterest (http://www.pinterest.com/instructables)

    Resources

    For Teachers (/teachers/)

    Artists in Residence (/group/air/)

    Sponsorships (/sponsorship/)

    Forums (/community/)

    Answers (/tag/type-question/)

    Mobile

    Download our new apps foriOS and android!

    Android

    (https://play.google.com/store/apps/details?

    id=com.adsk.instructables)

    iOS

    (https://itunes.apple.com/app/instructables/id586765571)

    Visit Our Store (http://store.instructables.com/)

    Go Pro Today (/account/gopro?sourcea=footer)

    let's make (http://usa.autodesk.com/adsk/servlet/pc/index?id=20781545&siteID=123112)

    Terms of service (/tos.html) | Privacy Policy (http://usa.autodesk.com/privacy/) | Mobile Site (http://m.instructables.com)