Go Down

Topic: Controlling Makershed 3x3 LED cube shield (Read 702 times) previous topic - next topic

Woffles

In case anyone is struggling with programming the 3x3 cube from MakerShed.  Doesn't really come with much information.

Code: [Select]

/*Wulf Robotics
//Inspiration for this from Joe Hudy
//Cube Sketch testing,, cubeFace function can handle inner and outer faces
*/
//Set column variables
//Set to HIGH to activate LED, front is with USB port facing you
int p1=10;  //Front Left
int p2=7;  //Front Middle
int p3=11;  //Front Right
int p4=6;  //Center Left
int p5=5;  //Center
int p6=A0;  //Center Right
int p7=2;  //Back Left
int p8=4;  //Back Middle
int p9=A5;  //Back Right

//Set Level variables
int lTop=A4;    //Set LOW to activate top layer LEDs
int lMid=A2;    //Set to LOW to activate mid layer LEDs
int lBot=A1;    //Set to LOW to activate bottom layer LEDs

void setup()
{
  //Set pins to OUTPUT mode
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(A5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A4, OUTPUT);
}

void loop()
{
  cubeFace(p1, p4, p7, LOW);    //turn off left face (Start here to keep look consistent in loop)
  cubeFace(p1, p2, p3, HIGH);    //turn on front face
  delay(250);  //slight pause
 
  cubeFace(p1, p2, p3, LOW);      //turn off front face
  cubeFace(p3, p6, p9, HIGH);    //turn on right face
  delay(250);
 
  cubeFace(p3, p6, p9, LOW);    //turn off right face
  cubeFace(p7, p8, p9, HIGH);    //turn on back face
  delay(250);

  cubeFace(p7, p8, p9, LOW);    //turn off back face
  cubeFace(p1, p4, p7, HIGH);    //turn on left face
  delay(250);
 
  cubeFace(p3, p6, p9, LOW);    //turn off right face
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on top face
  delay(250);  //pause
 
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off top face
  cubeFace(p1, p4, p7, HIGH);    //turn on left face
  delay(250);  //pause
 
  cubeFace(p1, p4, p7, LOW);    //turn off left face
  cubeBot(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on bottom face
  delay(250);  //pause
 
  cubeBot(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off bottom face
  cubeFace(p3, p6, p9, HIGH);    //turn on right face
  delay(250);

  cubeFace(p3, p6, p9, LOW);    //turn off right face
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on top face
  delay(250);  //pause

  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off top face
  cubeFace(p1, p4, p7, HIGH);    //turn on left face
  delay(250);  //pause
 
 
  cubeFace(p1, p4, p7, LOW);                            //turn off left face
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on top face
  delay(250);
 
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off top face
  cubeMid(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on mid face
  delay(250);
 
  cubeMid(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off mid face
  cubeBot(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on bottom face
  delay(250);

  cubeBot(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off bottom face
  cubeMid(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on mid face
  delay(250);

  cubeMid(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off mid face
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, HIGH);    //turn on top face
  delay(250);
 
  cubeTop(p1, p2, p3, p4, p5, p6, p7, p8, p9, LOW);    //turn off top face
  cubeFace(p1, p4, p7, HIGH);    //turn on left face
  delay(250);  //pause

  cubeFace(p1, p4, p7, LOW);    //turn off left face
  cubeFace(p2, p5, p8, HIGH);    //turn on front vertical slice
  delay(250);  //slight pause
 
  cubeFace(p2, p5, p8, LOW);      //turn off front vertical slice
  cubeFace(p3, p5, p7, HIGH);    //turn on right angle slice
  delay(250);
 
  cubeFace(p3, p5, p7, LOW);    //turn off right angle slice
  cubeFace(p4, p5, p6, HIGH);    //turn on mid face slice
  delay(250);

  cubeFace(p4, p5, p6, LOW);    //turn off mid face slice
  cubeFace(p1, p5, p9, HIGH);    //turn on left angle slice
  delay(250);
 
  cubeFace(p4, p5, p9, LOW);    //turn off left angle slice
  cubeFace(p2, p5, p8, HIGH);    //turn on front vertical slice
  delay(250);
 
  cubeFace(p2, p5, p8, LOW);      //turn off front vertical slice
  cubeFace(p1, p4, p7, HIGH);    //turn on left face
  delay(250);
}
 


 
  void cubeFace(uint8_t left, uint8_t middle, uint8_t right, uint8_t sig)    //get columns to choose which face to light from function call above
  {
    liteFace(left, middle, right, sig);      //pull values passed from original call to cubeFace and pass to liteFace function
   
    digitalWrite(lTop, LOW);  //turn on ground to top layer
    digitalWrite(lMid, LOW);  //turn on ground to middle layer
    digitalWrite(lBot, LOW);  //turn on ground to bottom layer
  }
     
  void liteFace(uint8_t left, uint8_t middle, uint8_t right, uint8_t sig) //pulls values from cubeFace and turns columns on or off
  {
    digitalWrite(left, sig);
    digitalWrite(middle, sig);
    digitalWrite(right, sig);
  }
   
  void cubeTop(uint8_t one,uint8_t two,uint8_t three,uint8_t four,uint8_t five,uint8_t six,uint8_t seven,uint8_t eight,uint8_t nine,uint8_t sig)
  {
      liteLayer(one,two,three,four,five,six,seven,eight,nine,sig);  //pull values passed from original call to cubeTop and pass to liteLayer function
     
      digitalWrite(lTop, LOW);  //turn on ground to top layer
      digitalWrite(lMid, HIGH);  //turn off ground to middle layer
      digitalWrite(lBot, HIGH);  //turn off groung to bottom layer
  }
 
    void cubeMid(uint8_t one,uint8_t two,uint8_t three,uint8_t four,uint8_t five,uint8_t six,uint8_t seven,uint8_t eight,uint8_t nine,uint8_t sig)
  {
      liteLayer(one,two,three,four,five,six,seven,eight,nine,sig);  //pull values passed from original call to cubeMid and pass to liteLayer function
     
      digitalWrite(lTop, HIGH);  //turn on ground to top layer
      digitalWrite(lMid, LOW);  //turn off ground to middle layer
      digitalWrite(lBot, HIGH);  //turn off groung to bottom layer
  }
 
    void cubeBot(uint8_t one,uint8_t two,uint8_t three,uint8_t four,uint8_t five,uint8_t six,uint8_t seven,uint8_t eight,uint8_t nine,uint8_t sig)
  {
      liteLayer(one,two,three,four,five,six,seven,eight,nine,sig);  //pull values passed from original call to cubeBot and pass to liteLayer function
     
      digitalWrite(lTop, HIGH);  //turn on ground to top layer
      digitalWrite(lMid, HIGH);  //turn off ground to middle layer
      digitalWrite(lBot, LOW);  //turn off groung to bottom layer
  }
 
 
  //activates LEDs for whole layer, variables passed from cubeTop, Mid and Bot functions
  void liteLayer(uint8_t one,uint8_t two,uint8_t three,uint8_t four,uint8_t five,uint8_t six,uint8_t seven,uint8_t eight,uint8_t nine,uint8_t sig)
  {
      digitalWrite(one,sig);

      digitalWrite(two,sig);

      digitalWrite(three,sig);

      digitalWrite(four,sig);

      digitalWrite(five,sig);

      digitalWrite(six,sig);

      digitalWrite(seven,sig);

      digitalWrite(eight,sig);

      digitalWrite(nine,sig);
}
     

Go Up