Pages: [1]   Go Down
Author Topic: 2x2x2 LED Cube  (Read 1381 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a cube that I made with the help of my Students. I have included the code since I couldn't find anything simple enough for me to use on the internet.

http://www.youtube.com/watch?v=7atiYegk3a0&feature=youtu.be
Code:
/*Code provided by Brian W. Cordes 2013*/

int ledpins[] = {3,5,6,9};
int groundpins[] = {12,13};
void setup ()
{
  for(int i = 0; i < 4; i++)
  {       
      pinMode(ledpins[i],OUTPUT);
  }                         
  for (int i= 0; i<2; i++)
  {pinMode(groundpins[i],OUTPUT);}

}

void loop()
{
 twist();
 drop();
 diagonal();
}

void twist()
{
  int delaytime=100;
   digitalWrite(groundpins[0], HIGH);
    delay(100);   
  digitalWrite(ledpins[0], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[1], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[2], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[3], HIGH);
  delay(delaytime);
 
   digitalWrite(ledpins[0], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[1], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[2], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[3], LOW); 
 delay(delaytime);
 digitalWrite(groundpins[0], LOW);
 
 
 
 
 digitalWrite(groundpins[1], HIGH);
    delay(100);   
  digitalWrite(ledpins[1], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[2], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[3], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[0], HIGH);
  delay(delaytime);
 
   digitalWrite(ledpins[1], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[2], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[3], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[0], LOW); 
  delay(delaytime);
  digitalWrite(groundpins[1], LOW);
 
 
  digitalWrite(groundpins[0], HIGH);
    delay(100);   
  digitalWrite(ledpins[2], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[3], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[0], HIGH);
  delay(delaytime);               
  digitalWrite(ledpins[1], HIGH);
  delay(delaytime);
 
  digitalWrite(ledpins[2], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[3], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[0], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[1], LOW); 
  delay(delaytime);
  digitalWrite(groundpins[0], LOW);
 
  digitalWrite(groundpins[1], HIGH);
    delay(100);   
  digitalWrite(ledpins[3], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[0], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[1], HIGH); 
  delay(delaytime);               
  digitalWrite(ledpins[2], HIGH);
  delay(delaytime);
 
  digitalWrite(ledpins[3], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[0], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[1], LOW); 
  delay(delaytime);               
  digitalWrite(ledpins[2], LOW); 
  delay(delaytime);
  digitalWrite(groundpins[1], LOW);
}

void drop()
{
  int dtime = 75;
  digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[0], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1],HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[0], LOW);
 
  digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[1], LOW);
 
  digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[2], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[2], LOW);
 
   digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[3], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[3], LOW);
 
 
  //second time down
  digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[0], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1],HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[0], LOW);
 
  digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[1], LOW);
 
  digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[2], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[2], LOW);
 
   digitalWrite(groundpins[0], HIGH);
  digitalWrite(ledpins[3], HIGH);
  delay(dtime);
  digitalWrite(groundpins[0], LOW);
  digitalWrite(groundpins[1], HIGH);
  delay(dtime);
  digitalWrite(groundpins[1], LOW);
  digitalWrite(ledpins[3], LOW);
 
 
}
 
void diagonal()
{
 int dtime= 100;
 //bottom pin 0 on
 digitalWrite(groundpins[1], HIGH);
 digitalWrite(ledpins[0], HIGH);
 delay(dtime);
 //bottom pin 0 off
 digitalWrite(groundpins[1], LOW);
 digitalWrite(ledpins[0], LOW);
 delay(dtime);
 //top pin 1 on
 digitalWrite(groundpins[0], HIGH);
 digitalWrite(ledpins[1], HIGH);
 delay(dtime);
 //top pin 1 off
 digitalWrite(groundpins[0], LOW);
 digitalWrite(ledpins[1], LOW);
 //bottom pin 2 on
 digitalWrite(groundpins[1], HIGH);
 digitalWrite(ledpins[2], HIGH);
 delay(dtime);
 //bottom pin 2 off
 digitalWrite(groundpins[1], LOW);
 digitalWrite(ledpins[2], LOW);
  //top pin 3 on
 digitalWrite(groundpins[0], HIGH);
 digitalWrite(ledpins[3], HIGH);
 delay(dtime);
 //top pin 3 off
 digitalWrite(groundpins[0], LOW);
 digitalWrite(ledpins[3], LOW);
 
 
 
 
 
 //top pin 0 on
 digitalWrite(groundpins[0], HIGH);
 digitalWrite(ledpins[0], HIGH);
 delay(dtime);
 //top pin 0 off
 digitalWrite(groundpins[0], LOW);
 digitalWrite(ledpins[0], LOW);
 delay(dtime);
 //bottom pin 1 on
 digitalWrite(groundpins[1], HIGH);
 digitalWrite(ledpins[1], HIGH);
 delay(dtime);
 //bottom pin 1 off
 digitalWrite(groundpins[1], LOW);
 digitalWrite(ledpins[1], LOW);
 //top pin 2 on
 digitalWrite(groundpins[0], HIGH);
 digitalWrite(ledpins[2], HIGH);
 delay(dtime);
 //top pin 2 off
 digitalWrite(groundpins[0], LOW);
 digitalWrite(ledpins[2], LOW);
  //bottom pin 3 on
 digitalWrite(groundpins[1], HIGH);
 digitalWrite(ledpins[3], HIGH);
 delay(dtime);
 //bottom pin 3 off
 digitalWrite(groundpins[1], LOW);
 digitalWrite(ledpins[3], LOW);
 
 }
Logged

Melbourne, Australia
Offline Offline
Jr. Member
**
Karma: 6
Posts: 88
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well done, simple and a lot of fun smiley
Logged

Check out my Arduino tutorials at http://tronixstuff.com/tutorials - Order my new Arduino book from http://www.arduinoworkshop.com

Pages: [1]   Go Up
Jump to: