3X3X3 LED cube

Hello everyone!
Before I start properly,
XD I just had to test this out XD

Anyway, back to the point...
I've finally completed a project that I started some time back.
As the title hints, it is a 3X3X3 LED cube. Using 27 LEDs, it creates
some cool patterns and effects. I used two codes for this project.
The first one was boring, so I re-wrote it to be much more exciting.
Now, it is 8 pages long (size 11 on word), 359 lines long, and 6246
characters. This means that I will have to keep the description
brief to fit in everything.

The code is here:

int Abrightness = 0;
int Bbrightness = 0;
int Cbrightness = 0;
int brightness = 0;

int LED;
int layer;
int pin;
int func;


//pin declerations:
//verticle coloumbs:
#define axay 53
#define axby 52
#define axcy 51
#define bxay 46
#define bxby 47
#define bxcy 45
#define cxay 41
#define cxby 40
#define cxcy 39
//horisontal layers:
const int layerA = 9;
const int layerB = 8;
const int layerC = 10;

/* A note for pin names:
 All the pins use the XY graphing formation, hence the second letter being
 an x and the last being a y. Having numbers in the pin decleration confuses 
 it though, so the number 1 has been replaced with the letter A, the number 2
 has been replaced with the letter B and the number 3 has been replaced with the
 letter C. The bottom layer is layer a, the middle is bottom b and the top layer is 
 layer c. (The LEDs in each layer are arranged like this:
 
 axcy    bxcy    cxcy
 
 axby    bxby    cxby
 
 axay    bxay    cxay
 
 )
 
 */

void funcA();
void funcB();
void funcC();
void funcD();
void funcE();
void funcF();


void setup(){
  randomSeed(analogRead(A0));
  pinMode(axay, OUTPUT);
  pinMode(bxay, OUTPUT);
  pinMode(cxay, OUTPUT);
  pinMode(axby, OUTPUT);
  pinMode(bxby, OUTPUT);
  pinMode(cxby, OUTPUT);
  pinMode(axcy, OUTPUT);
  pinMode(bxcy, OUTPUT);
  pinMode(cxcy, OUTPUT);
}


void loop(){

  //TURN ALL PINS OFF
  digitalWrite(axay, LOW);
  digitalWrite(bxay, LOW);
  digitalWrite(cxay, LOW);
  digitalWrite(axby, LOW);
  digitalWrite(bxby, LOW);
  digitalWrite(cxby, LOW);
  digitalWrite(axcy, LOW);
  digitalWrite(bxcy, LOW);
  digitalWrite(cxcy, LOW); 
  analogWrite(layerA, 0);
  analogWrite(layerB, 0);
  analogWrite(layerC, 0);

  Abrightness = 0;
  Bbrightness = 0;
  Cbrightness = 0;

  delay(50);

  func = random(1,5);

  switch(func){
  case 1:
    funcA();
    break;

  case 2:
    funcB();
    break;

  case 3:
    funcC();

  case 4:
    funcD();
    break;

  case 5:
    funcE();
    break;
  }
}






void funcA(){

  digitalWrite(axay, HIGH);
  digitalWrite(bxay, HIGH);
  digitalWrite(cxay, HIGH);
  digitalWrite(axby, HIGH);
  digitalWrite(bxby, HIGH);
  digitalWrite(cxby, HIGH);
  digitalWrite(axcy, HIGH);
  digitalWrite(bxcy, HIGH);
  digitalWrite(cxcy, HIGH);

  for(int i = 0; i != 255; i++){
    analogWrite(layerA, Abrightness);
    Abrightness++;
    delay(1);
  }
  for(int i = 0; i != 255; i++){
    analogWrite(layerB, Bbrightness);
    Bbrightness++;
    analogWrite(layerA, Abrightness);
    Abrightness--;
    delay(1);
  }
  for(int i = 0; i != 255; i++){
    analogWrite(layerC, Cbrightness);
    Cbrightness++;
    analogWrite(layerB, Bbrightness);
    Bbrightness--;
    delay(1);
  }
  for(int i = 0; i != 255; i++){
    analogWrite(layerC, Cbrightness);
    Cbrightness--;
    delay(1);
  }
}


void funcB(){
  digitalWrite(axay, HIGH);
  digitalWrite(bxay, HIGH);
  digitalWrite(cxay, HIGH);
  digitalWrite(axby, HIGH);
  digitalWrite(bxby, HIGH);
  digitalWrite(cxby, HIGH);
  digitalWrite(axcy, HIGH);
  digitalWrite(bxcy, HIGH);
  digitalWrite(cxcy, HIGH); 

  for(int i = 0; i != 255; i++){
    analogWrite(layerA, Abrightness);
    Abrightness++;
    delayMicroseconds(500);
  }
  for(int i = 0; i < 4; i++){
    analogWrite(layerA, 255);
    delay(250);
    analogWrite(layerA, 0);
    analogWrite(layerB, 255);
    delay(250);
    analogWrite(layerB, 0);
    analogWrite(layerC, 255);
  }
}

void funcC(){
  analogWrite(layerA, 255);
  analogWrite(layerB, 255);
  analogWrite(layerC, 255);
  digitalWrite(bxby, HIGH);

  for(int i = 0; i < 2; i++){

    digitalWrite(axby, HIGH);
    digitalWrite(cxby, HIGH);

    delay(100);

    digitalWrite(axby, LOW);
    digitalWrite(cxby, LOW);
    digitalWrite(cxay, HIGH);
    digitalWrite(axcy, HIGH);

    delay(100);

    digitalWrite(cxay, LOW);
    digitalWrite(axcy, LOW);
    digitalWrite(bxcy, HIGH);
    digitalWrite(bxay, HIGH);

    delay(100);

    digitalWrite(bxcy, LOW);
    digitalWrite(bxay, LOW);
    digitalWrite(axay, HIGH);
    digitalWrite(cxcy, HIGH);

    delay(100);

    digitalWrite(axay, LOW);
    digitalWrite(cxcy, LOW);
    digitalWrite(axcy, HIGH);
    digitalWrite(cxby, HIGH);

    delay(100);

    digitalWrite(axcy, LOW);
    digitalWrite(cxby, LOW);
    digitalWrite(axcy, HIGH);
    digitalWrite(cxby, HIGH);

    delay(100);

    digitalWrite(axcy, LOW);
    digitalWrite(cxby, LOW);
    digitalWrite(bxcy, HIGH);
    digitalWrite(bxay, HIGH);

    delay(100);

    digitalWrite(bxcy, LOW);
    digitalWrite(bxay, LOW);
    digitalWrite(axay, HIGH);
    digitalWrite(cxcy, HIGH);

    delay(100);

    digitalWrite(axay, LOW);
    digitalWrite(cxcy, LOW);    
  }
}

void funcD(){
  int delayTime = 200;
  for(int i = 0; i != 10; i++){
    delayTime = delayTime - 10;
    LED = random(1,9);
    layer = random(1,3);

    switch(LED){
    case 1:
      digitalWrite(axay, HIGH);
      pin = axay;
      break;

    case 2:
      digitalWrite(axby, HIGH);
      pin = axby;
      break;

    case 3:
      digitalWrite(axcy, HIGH);
      pin = axcy;
      break;

    case 4:
      digitalWrite(bxay, HIGH);
      pin = bxay;
      break;

    case 5:
      digitalWrite(bxby, HIGH);
      pin = bxby;
      break;

    case 6:
      digitalWrite(bxcy, HIGH);
      pin = bxcy;
      break;

    case 7:
      digitalWrite(cxay, HIGH);
      pin = cxay;
      break;

    case 8:
      digitalWrite(cxby, HIGH);
      pin = cxby;
      break;

    case 9:
      digitalWrite(cxcy, HIGH);
      pin = cxcy;
      break;
    }

    switch(layer){
    case 1:
      analogWrite(layerA, 255);
      delay(delayTime);
      digitalWrite(pin, LOW);
      analogWrite(layerA, 0);
      break;

    case 2:
      analogWrite(layerB, 255);
      delay(delayTime);
      digitalWrite(pin, LOW);
      analogWrite(layerB, 0);
      break;

    case 3:
      analogWrite(layerC, 255);
      delay(delayTime);
      digitalWrite(pin, LOW);
      analogWrite(layerC, 0);
      break;
    }
  }
}

void funcE(){

  digitalWrite(axay, HIGH);
  digitalWrite(bxay, HIGH);
  digitalWrite(cxay, HIGH);
  digitalWrite(axby, HIGH);
  digitalWrite(bxby, HIGH);
  digitalWrite(cxby, HIGH);
  digitalWrite(axcy, HIGH);
  digitalWrite(bxcy, HIGH);
  digitalWrite(cxcy, HIGH); 
  for(int i = 0; 0 != 256; i++){
    analogWrite(layerA, brightness);
    analogWrite(layerB, brightness);
    analogWrite(layerC, brightness);
    brightness++;
    delay(2);
  }

  delay(250);

  for(int i = 0; 0 != 256; i++){
    analogWrite(layerA, brightness);
    analogWrite(layerB, brightness);
    analogWrite(layerC, brightness);
    brightness--;
    delay(1);
  }
}

I wrote all of the second code in a night or two. The hardware took a couple
of nights to complete, but I ended up doing several projects in between
building the hardware and writing the new software, so it was a month
or two between starting and finnishing.

Here is a video to show everything:

The cube uses 5 functions, all written in the software, then randomly selects one
to create lots of interesting effects. As it is only a small cube, it uses no
multiplexers and can be controlled from the duemillanove, uno, or something
similar. Now, I wonder why I used the mega instead. Ah well...

Hope you like it!
Onions.

Nice work!

CrossRoads:
Nice work!

Thanks!
Sometime soon, I will write a new code, with more functions, and I will add in some functions with POV. Although it is pretty useless, it sounds like a fun challenge!

Nice! I've been working on mine for a while now. Putting it into a project box. I laid out the circuit on a protoboard but when I apply power nothing happens. I have a short somewhere. Need to find it.

I'll share when it's done and working.

Putting it into a project box.

You're better than me! Mine will get no fancier than it is now (hardware wise) - all the solder joints and wires will stay on show.

You could put it in a clear acrylic box so it is protected yet still all visible.
Maybe find an old snowglobe & reuse it?

You could put it in a clear acrylic box so it is protected yet still all visible.

That sounds like a good idea! Maybe I will do it after all...

Maybe find an old snowglobe & reuse it?

A snowglobe might be too small, but if it fits, it would be brilliant. If it doesn't, I could buy some perspex sheets and glue them into a box shape using airfix model glue. I'll have to look at my local DIY shop some time soon.
XD

Onions:

CrossRoads:
Nice work!

Thanks!
Sometime soon, I will write a new code, with more functions, and I will add in some functions with POV. Although it is pretty useless, it sounds like a fun challenge!

oh geez, POV - I never thought of that - get a demo up soon!

edit: wait now, POV would mean moving the whole thing wouldn't it?

Sure, put the whole thing (with battery pack, or two brush contacts for power/ground) on top of a motor and twirl away!

oh geez, POV - I never thought of that - get a demo up soon!

I will put up a demo, if I ever end up completing it! XD Hopefully I will do it, but it might be several months in the future...

Onions:
You're better than me! Mine will get no fancier than it is now (hardware wise) - all the solder joints and wires will stay on show.

Well overall it will look OK but my cube is kind of funky shaped. Figured putting it in a nice enclosure would make it look better. :stuck_out_tongue:

It's real close. Just needs an hour or 2 more work and I'll be done. Then I'll post up my own thread and stop hijacking yours. :stuck_out_tongue:

Figured putting it in a nice enclosure would make it look better.

And it does, it's looking very good!
Was that the RBBB I noticed in the bottom picture? It is something I need to treat myself to some time.
:smiley:

RBBB - what do you normally use instead?

Yes, I bought 2 RBBBs un-assembled, one for this project and one or the next one I'll be working on. Then I figured I'd have enough practice to try one on my own. I made a ton of mistakes on this board but overall I'm happy with it.

I was going to mention and forgot to, I picked up a 20 pin ribbon cable which I'll be soldering directly to the leads on the bottom of the box. That will then connect to the header pins on the board.

Oh, and the holes for power (round) and pattern (square) are rough but the buttons cover them up and hide the rough edges. The 'pattern' button will cycle through the 8 or 10 patterns I have programmed in.

I was going to mention and forgot to, I picked up a 20 pin ribbon cable which I'll be soldering directly to the leads on the bottom of the box. That will then connect to the header pins on the board.

That's a brilliant idea!
I just used a piece of stripboard (in the photo) and made it up as I want along. By not using a plan, it had the disadvantage that I could not tell if something was connected onto a strip or not. I think this probably has something to do with the transistors not working.

RBBB - what do you normally use instead?

A duemillanove, or a MEGA (old version).
I don't suppose anyone knows where I can buy a RBBB the UK, for if I eventually do buy one?
Thanks!
Onions.

Escribe texto o la dirección de un sitio web, o bien, traduce un documento.
Cancelar
Escuchar
Leer fonéticamente
traducción del español al inglés
hello
please help me with something very urgent
I have already created all my hardware
3x3x3 cube
ATmega328 board
but most importantly I need the code
you are giving him but that compiler charge it to the board
Help .....!!!!!!!!!!!!!!! 1 :drooling_face: :drooling_face: :drooling_face: :drooling_face: :drooling_face: :drooling_face: :drooling_face: :drooling_face: :drooling_face: :drooling_face:
please ....!!!!!!!!!!!!!!!! 1 :cold_sweat: :cold_sweat: :cold_sweat: :cold_sweat: :cold_sweat: :cold_sweat: :cold_sweat: :cold_sweat: