Arduino 3x3x3 Cube Code

Post here to discuss all things Arduino!

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Arduino 3x3x3 Cube Code

Post by Saimaster13 » Tue Oct 09, 2012 6:57 am

I just made a 3x3x3 cube code for the Arduino from scratch. It does not have full notes, though it has some. The animations are written in octal.

This code assumes that the layers are cathodes and the columns are anodes.

To hook it up, you have to do is hook pins 2, 3, and 4 to the layers, starting with the bottom one.
It should look something like:
4 Top
3 Middle
2 Bottom


Now the column pins are pins 5-13. Hook them up left to right starting from the back, then to the middle, then front.
It should look something like this:

5 6 7 back
8 9 10 middle
11 12 13 front


Don't forget whatever resistors needed, then it should be all hooked up.

Here is how to program it:

1. Find the animation1[][5] variable.
2. Write the desired code in octal (convert desired binary number to octal)
The code looks something like this: {0123, 0123, 0123, 1999} note: the 8 and 9 are INVALID characters since it is written in octal!
The 0s (zeros) in front of the first three numbers need to stay there, it tells the Arduino that it is an octal number.
The first number, the first "0123" in the example, is the bottom layer. The characters in it go from back to front. So, the 1 is the back column group, 2 is the middle column group, 3 the front column group.
The second number, also "0123", is the middle row. Same thing goes for the column groups.
The third number is obviously the top row
The last number though (the fourth one) is the delay. Since it is 1999, it will stay on that animation step for 1.999 seconds).

3. The code does NOT have an automatic end, so you will have to insert a manual one. instead of the original code in the animation (such as "{0123, 0123, 0123, 1999},") you will need to insert "{END}"





Good luck guys, I would love to hear the complaints and comments.


Code: Select all

//a 3x3x3 LED cube for the arduino, direct connecting the pins.
//Originally made by Joshua Little 10/8/12
//Open source

byte cubePin[13] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; /*The pins going to the cube. The first three are the 3 rows, and the other 9 are the columns.
                                                               The rows go from buttom to top, and the columns go from left to right, back to front
                                                               Default: {2, 3, 4, 5 ,6 ,7 ,8 ,9 10, 11, 12, 13}
                                                               
                                                               Rows:   4 top                         Comumns:  5  6  7      farthest away from the front            
                                                                       3 middle                                8  9  10     middle
                                                                       2 bottom                                11 12 13    the closest LEDs to you   */
                                                                       
                                                                       
unsigned int END = 63013; //Tells the animation to loop back to the begining. The value is a random value that will not conflict with the 3 digit octal values in the animations                                                                       
                                                                       
 //the animations to be played written in octal. It REQUIRES the 0 in front of the number. The last number is the delay.
//the first number after the initial 0 is the 3 back columns, second is 3 middle ones, and third is 3 front ones
//the first 0xxx number is the bottom row, second middle row, third top row
//so, if I wanted a the bottom row to look like this: 0 1 0      I would convert the top column set to octal: 2
//                                                    1 0 1      Then convert the middle column set: 5
//                                                    0 1 0      Bottom: 2
// So the first number in the set would be: 0252. 
//If you wanted all 3 rows to be the same and the delay to be 250ms (0.25sec), then you would put {0252, 0252, 0252, 250}
int animation1[][5] = {                              
{0700, 0070, 0007, 250},
{0000, 0777, 0000, 250},  
{0007, 0070, 0700, 250},
{0070, 0070, 0070, 250},
{END}                            //tells the animation to return to the first step
}; 

unsigned long time;  //millis()
unsigned long timer; //the amount of time past since the last animation step
int timerCount = 0;  // the amount of animations steps past




int rowData[2][4] = {{0, 0, 0}}; //temporarily stores the animation step values to display them on the cube.





void setup(){
  for(int x=0; x < 14; x++){ //sets the cube pins as outputs
    pinMode(cubePin[x], OUTPUT);
  }
}


void loop(){
  time = millis(); //time is the amount of time the Arduino has been on 
  cubeDisplayUpdate(); //computes what animation step should be played 
  cubeDisplay();  //displays the chosen animation step
}


void cubeDisplay(){
  for(int y = 0; y < 3; y++){ //start with the bottom row then go to the middle, then top
    digitalWrite(cubePin[y], LOW);  //turns on the current row                                !!!if the rows are anodes, then this should be HIGH. If they are cathodes, set to LOW.
    for(int x = 0; x < 9; x++){ 
      if(bitRead(rowData[0][y], (8-x))==1){ //turns on the LEDs in the current row
        digitalWrite(cubePin[(3+x)], HIGH); //3+x is the first                              !!!if the columns are anodes, then this should be HIGH. If they are cathodes, set to LOW.
      }
    }
    for(int x = 0; x < 9; x++){ //turns off the all the column LEDs
      digitalWrite(cubePin[3+x], LOW);  //                                                    !!!if the columns are anodes, then this should be LOW. If they are cathodes, set to HIGH.
    }
    digitalWrite(cubePin[y], HIGH); //turns off the current row                               !!!if the rows are anodes, then this should be LOW. If they are cathodes, set to HIGH.
  }
}


void cubeDisplayUpdate(){  
  if(time >= (timer + animation1[timerCount][3])){ //switches the animation step once the animation delay time has been reached
    timerCount++; //timerCount decides which animation step to display
    timer = time; //updates timer to the amount of time the arduino has been on. This allows the arduino to tell the amount of time since the steps were changed.
  }
  if(animation1[timerCount][0]==END){ //if {END} is found in the animation code, then go back to the first animation step
    timerCount = 0;
  }
  for(int x = 0; x < 3; x++){
    rowData[0][x] = animation1[timerCount][x];   //updates the current animation step to the rowData string
  }
  
}
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino 3x3x3 Cube Code

Post by brad » Thu Oct 11, 2012 11:20 pm

Thanks for sharing. I think these cubes are really cool - but I have never been game to make one.

I have been looking through your code - what animations does it produce?

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino 3x3x3 Cube Code

Post by Saimaster13 » Fri Oct 12, 2012 12:06 am

I've always loved cubes, this is the first time I've been able to make a microcontroller one. The animation is very basic, I just slapped one together. It is just a plane flipping around the center of the cube (kind of like this / | \ - / | \ - if it makes sense, its hard to type a visual...)

Anyway, I'll be sure to add a video when I'm done with the hardware. (I tested the LED code on a small crappy looking cube with a burnt out LED and some connections that do not connect to where they are supposed to, so I had to alligator clip them)
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino 3x3x3 Cube Code

Post by brad » Fri Oct 12, 2012 9:36 am

Cool! - look forward to it :)

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino 3x3x3 Cube Code

Post by Saimaster13 » Sat Oct 20, 2012 2:40 pm

The LED cube doesn't really record well, but it looks pretty good in person.

Anyway, finally got to putting it together, and although it isn't finished, it is running.

Here are two videos:


Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino 3x3x3 Cube Code

Post by brad » Sun Oct 21, 2012 9:37 pm

Thanks for uploading the videos! Its pretty cool that even a low resolution display like this can still create some pretty cool animations.

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 5 guests