My first Arduino project. 3x3x3 cube

Great job RosDaddy, ten points.

I am definitely no coding expert, and all that I have learned has been with the help of the members of this great forum. Also studying and trying to understand, then implement / modify any code that you can find is of enormous help. I would suggest looking at arrays and for loops initially.

Have a look at this code and see what you can do. There are much better cube code examples on this forum and the net generally but if you can see how this works you will be making an improvement in your coding prowess 8)

/* 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 assume that your cube is wired so that the nine LED's on any one level are led1 to led9, and the three levels are A1, A2 and A3. If so and you want to try the attached code, just change your cube to Arduino wiring to –

Led1 to led9 Arduino pins 2 to 10. And leave led1 led2 and led3 as they are connected to Arduino pins 11, 12 and 13. Upload the attached code and have a look and see what it is doing. As I said I am certainly no expert but hey it's all a fun learning process.

Regarding the use of transistors I would definitely listen to Crossroads advice. He is one of the best hardware guru's on the forum.

Have fun Pedro. 8)