Go Down

Topic: My First Cube (Read 725 times) previous topic - next topic

Muffy

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

Nelsyv

http://youtu.be/cKF0bJtYMck

I watched the video, very cool! I think you will be able to do some interesting things with this ;)
Give a man a wiring diagram, he builds for a day. Teach him how to make his own, and he builds until he runs out of parts :P

Pedro147

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
Quote
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 -

http://www.youtube.com/watch?v=uTaN-UfZFXI

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: [Select]
/* 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


Hippynerd

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.

Muffy

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 :)

thanks again guys.

Go Up