My First Cube

Hi All.
Im new to Arduino, only been playing for 3-4 weeks.
I have made my first 3x3x3 cube and wrote all the code myself.

I feel I have done a great job with the code keeping it simple yet functional, so i thought I would share it with everyone.

Any feedback or suggested improvements would be great.

Video and all detail can be found: http://www.muffymc.com.au/?p=103

I watched the video, very cool! I think you will be able to do some interesting things with this :slight_smile:

Muffy,

all I can say is well done what an interesting piece of coding. I keep saying this on this forum how do you guys that

Im new to Arduino, only been playing for 3-4 weeks.

manage to get a grasp of and seemingly master all this so quickly. Here is my humble effort -

I am not sure why but when I run your code on my 3 x 3 x 3 common cathode cube the LED brightness is reduced to approx 60% of what it is if I run this code

/* Code by Pedro147 inspired by this -
 
 http://www.abrushfx.com/Arduino/ledcube3.html
 
*/

int ledRow[] = { 11, 12, 13 };
int ledCol[]= { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int timer= 10;




void setup() 
{  
  for( int i =  0; i < 3; i++)

  {
    pinMode( ledRow[i],OUTPUT);
  }

  {  
    for(int j =  0; j < 9; j++)

    {
      pinMode( ledCol[j],OUTPUT);
    }
  }
}


void onLED(int ledRow, int ledCol){

  digitalWrite(ledRow, HIGH); 
  digitalWrite(ledCol, HIGH); 

}


void offLED(int ledRow, int ledCol)
{
  digitalWrite(ledRow, LOW); 
  digitalWrite(ledCol, LOW); 
}


void allOff()
{
  for(int i = 3; i--;)
  {
    for(int j = 9; j--;)
    {
      offLED(ledRow[i],ledCol[j]);
    }
  }
}


void oneToNine_ColsOn()
{
  for(int j = 9; j--;)

  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}


void everySecond_ColsOn1()
{

  for(int j = 0; j< 9; j+=2)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}


void everySecond_ColsOn_2()
{

  for(int j = 1; j< 9; j+=2)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
} 
void lhWall_fToR()

{

  for(int j = 0; j< 9; j+=3)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}

void rhWall_fToR()

{

  for(int j = 2; j< 9; j+=3)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}


void frontWall_LtoR()
{
  for(int j = 0; j< 3; j++)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}

void rearWall_LtoR()
{
  for(int j = 6; j<9; j++)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(10);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}


void centreWall_LtoR()
{
  for(int j = 3; j<6; j++)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(timer);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}

void centreWall_fToR()

{

  for(int j = 1; j< 9; j+=3)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(timer);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}

void diagWall_LtoR()
{
  for(int j = 0; j < 9; j+=4)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(timer);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}

void diagWall_RtoL()
{
  for(int j = 2; j < 8; j+=2)
  {
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(timer);
      digitalWrite(ledCol[j], HIGH);
    }
  }
}

void rowPaneFigure8()
{
  for (int i = 0; i < 3; i++)

  {
    for(int j = 0; j < 3; j++)   // light LED's 1 - 3 on/off on top level

    {
      onLED(ledRow[i],ledCol[j]);         // 7 8 9
      delay(timer);                       // 4 5 6
      offLED(ledRow[i],ledCol[j]);        // 1 2 3
    }
    for(int j = 5; j > 2; j--)  // light LED's 6 - 4 on/off on top level
    {
      onLED(ledRow[i],ledCol[j]);
      delay(timer);
      offLED(ledRow[i],ledCol[j]);
    }
    for(int j = 6; j < 9; j++)  // light LED's 7 - 9 on/off on top level
    {
      onLED(ledRow[i],ledCol[j]);
      delay(timer);
      offLED(ledRow[i],ledCol[j]);
    }
    for(int j = 5; j > 2; j--)   // light LED's 6 - 4 on/off on top level
    {
      onLED(ledRow[i],ledCol[j]);
      delay(timer);
      offLED(ledRow[i],ledCol[j]);
    }

  }

}

void frontTorear_flash1()
{
  for(int j = 0; j < 9; j+=3)
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(20);
      digitalWrite(ledCol[j], HIGH);
    }
}


void frontTorear_flash2()
{
  for(int j = 1; j < 9; j+=3)
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(20);
      digitalWrite(ledCol[j], HIGH);
    }
}


void frontTorear_flash3()
{
  for(int j = 2; j < 9; j+=3)
    for(int i = 3; i--;)
    {
      digitalWrite(ledRow[i], HIGH);
      delay(20);
      digitalWrite(ledCol[j], HIGH);
    }
}

void randomColumnsOnOff()
{
  int colmax = 9;
  int stCol  = random(0,colmax);

  {
    digitalWrite(ledRow[0], HIGH); 
    digitalWrite(ledCol[stCol], HIGH); 
    digitalWrite(ledRow[1], HIGH); 
    digitalWrite(ledCol[stCol], HIGH); 
    digitalWrite(ledRow[2], HIGH); 
    digitalWrite(ledCol[stCol], HIGH); 
    delay(timer);
    allOff();



  }
}
void loop()
{
  oneToNine_ColsOn();
  delay(10);
  allOff();
  delay(10);
  everySecond_ColsOn1();
  delay(10);
  allOff();
  delay(10);
  everySecond_ColsOn_2();
  delay(10);

  oneToNine_ColsOn();
  delay(10);
  allOff();
  delay(10);
  everySecond_ColsOn1();
  delay(10);
  allOff();
  delay(10);
  everySecond_ColsOn_2();
  delay(10);


  lhWall_fToR();
  delay(100);
  allOff();
  centreWall_fToR();
  delay(100);
  allOff();
  rhWall_fToR();
  delay(100); 
  allOff();

  frontWall_LtoR();
  delay(100);
  allOff();
  centreWall_LtoR();
  delay(100);
  allOff();
  rearWall_LtoR();
  delay(100);
  allOff();

  rowPaneFigure8();

  centreWall_LtoR();
  allOff();
  diagWall_LtoR();
  allOff();
  centreWall_fToR();
  allOff();
  diagWall_RtoL();
  allOff();
  frontTorear_flash1();
  delay (timer);
  allOff();
  frontTorear_flash2();
  delay (timer);
  allOff();
  frontTorear_flash3();
  delay (timer);
  allOff();
  randomColumnsOnOff();
  randomColumnsOnOff();
  randomColumnsOnOff();
}

I know you say you are new to Arduino but any ideas. Thanks again for the great code and I look forward to seeing anymore of your Arduino forays, Pedro

Nice cube, I like how simple it is to control the cube with your program. It reminds me of a cube I was looking at last week (its much a more complex cube, but controlling the cube, was very similar.)

Pedro, a person can be new to arduino, but not new to electronics, or programming. It could be that muffy has similar experiences that have helped. It is just as likely that muffy could learn something from you too.

Hey, Thanks for the comments.
Yea, new to Arduino, have done electronics from age 5 to 14 then stopped for 10 years and started programming.
Its great to be able to Integrate programming with Hardware.
Its a great learning platform as well for programming and electronics, sort of killing two birds with one stone.

What value resistors are you using Pedro?

Im about to start a 8x8x8 cube using 595 (8 for all columns and a 9th for layer control)
A complete code redesign to be for flexible with animation rather then just frame-by-frame definition.
But will take a while because my first child is due in 2 weeks :slight_smile:

thanks again guys.

I have a few 4x4x4 RGB cubes going, and one will use 595s, but after getting it about half way built, I realized that each chip only supports 70ma, so I will have to reduce each LED to under 10ma to keep them in the 70ma limit :frowning:
I have used these specific chips at well over 70ma, using the shiftpwm and shift out demos, so I know the parts wont instantly vaporize, but you may wear out your 595s quickly. I often see TPICB595 chips recommended for people that need more than 70ma per 8-bit.

When you use shift registers, you will be changing from serial to parallel data, In an 8x8x8 cube where you control one plane at a time, you will probably be lighting up to 64 LEDs at a time.

There is currently another thread going about 8x8x8 cube using the tpic part, its rather long, but the end has a nice looking setup. There are a few hardware variations depending on what parts you may want to use, but Im pretty sure everything you need to know is in that thread.

Muffy,

I am using 220 ohm resistors in my cube, but it is strange that I can use many different codes and they are all bright whereas your code only illuminates the LED's to approx 60%. Must be Gremlins ... makes no sense oh well