3x3x3 Cube

/* Cube Project

*/ int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by

void setup() { // declare 2-13 to be an output: pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); }

void loop() { // set the brightness of pin outputs: analogWrite(6, brightness); digitalWrite(11, HIGH); digitalWrite(12, HIGH); digitalWrite(13, HIGH); delay(50); analogWrite(2, brightness); delay(50); analogWrite(2, LOW); delay(50); analogWrite(3, brightness); delay(50); analogWrite(3, LOW); delay(50); analogWrite(4, brightness); delay(50); analogWrite(4, LOW); delay(50); analogWrite(7, brightness); delay(50); analogWrite(7, LOW); delay(50); analogWrite(10, brightness); delay(50); analogWrite(10, LOW); delay(50); analogWrite(9, brightness); delay(50); analogWrite(9, LOW); delay(50); analogWrite(8, brightness); delay(50); analogWrite(8, LOW); delay(50); analogWrite(5, brightness); delay(50); analogWrite(5, LOW); delay(50); analogWrite(6, LOW); delay(20); digitalWrite(11, brightness); digitalWrite(12, brightness); digitalWrite(13, brightness); digitalWrite(2, brightness); digitalWrite(3, brightness); digitalWrite(4, brightness); delay(50); analogWrite(2, LOW); analogWrite(3, LOW); analogWrite(4, LOW); delay(50); digitalWrite(5, brightness); digitalWrite(6, brightness); digitalWrite(7, brightness); delay(50); analogWrite(5, LOW); analogWrite(6, LOW); analogWrite(7, LOW); delay(50); digitalWrite(8, brightness); digitalWrite(9, brightness); digitalWrite(10, brightness); delay(50); analogWrite(8, LOW); analogWrite(9, LOW); analogWrite(10, LOW); delay(50); digitalWrite(2, brightness); digitalWrite(5, brightness); digitalWrite(8, brightness); delay(50); analogWrite(2, LOW); analogWrite(5, LOW); analogWrite(8, LOW); delay(50); digitalWrite(3, brightness); digitalWrite(6, brightness); digitalWrite(9, brightness); delay(50); analogWrite(3, LOW); analogWrite(6, LOW); analogWrite(9, LOW); delay(50); digitalWrite(4, brightness); digitalWrite(7, brightness); digitalWrite(10, brightness); delay(50); analogWrite(4, LOW); analogWrite(7, LOW); analogWrite(10, LOW); delay(50);

// change the brightness for next time through the loop: brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect delay(50); }

Okay, you need to back up a bit - only 6 pins have analogWrite capability: 3,5,6,9,10,11. Can't offer more help without knowiing how you're wired up. For a 3x3x3, I would go with 9 ardiuno outputs driving 3 the anodes of LEDs in parallel, 1 set making up 1 each row, and then 3 more pins driving a transistor or a ULN2003 to sink the current from each row. Then you could PWM each row , or perhaps 6 of the 9 LEDs in each row.

For example:

If you can't rewire it, could you give us an idea on how it is wired?

Either way I think you could delay in microseconds between each time you turn it on with the time increasing with every cycle. Using mine I can't see any difference at a couple milliseconds so adding more of a delay should not be visible other than dimming the light.

Sorry having a hard time logging back in.
Anyway anodes tied to anodes, cathodes tied to cathodes. anodes tied to 2-10(columns) and levels tied to 11-13 thru an NPN. I got instruction on the how to build an LED cube off the nets top results.

234
567
8910

thats how I ran my wires in that order looking down.

11
12
13 < this order 13 being bottom level.

In all honesty I could figure it out with one example letter. Its just the matter of progression and understanding basically how to use the resources I have at hand. Which is why I created an account. I'm new to electronics and new to programming. So please don't get annoyed. LOL. I have had MP's, AC/DC, Digital, C, and etc. so I'm coming along better than the rest in class.

Okay, so it’s wired in levels with each anode having it’s own pin and each layer sharing all the cathodes for that layer.
Same way I have mine except with no shift registers.

Try this:

int currentLine = 13;
int runs = 0;

void setup()  {
  // declare 2-13 to be an output:
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
} 

void loop()
{
    while(currentLine > 10)
    {
    for(int i = 2; i < 11; i++)
    {
        digitalWrite(i, HIGH);
    }
  
    delayMicroseconds(50);

    for(int j = 2; j < 11; j++)
    {
        digitalWrite(j, HIGH);     
    }

     delayMicroseconds(runs);

    currentLine--;
    }

    runs += 1;
     currentLine = 13;
}

I wrote this in the browser so you may have to debug it.
Lol.

No problem.
How about this then for PWMing 27 LEDs in a 3x3x3 cube.
Create three 9 byte arrays.
At each location, store the PWM value of that LED.
Write each LED high to enable it, and put the PWM value on its NPN transistor.
Loop thru all three arrays quickly so it looks like all are active.

Actually, this method only drives 1 LED at a time, so no NPN transistor is needed.

byte layer1[]= {
  25,50,75,100,125,150,175,200,225};// arbitrary starting values
byte layer2[]= {
  25,50,75,100,125,150,175,200,225};
byte layer3[]= {
  25,50,75,100,125,150,175,200,225};
byte rowPins[ ] = {
  2,3,4,5,6,7,8,14,15}; // 14, 15 are A0, A1
byte cathodePins [ ]= {
  9,10,11}; // PWMable pins
byte LED=0;
byte row=0;
byte cathode=0;

void setup(){
  // set up output pins, turn all off
  for (LED = 0; LED<9;LED=LED+1){
    pinMode(rowPins[LED], OUTPUT);
    digitalWrite (rowPins[LED], LOW);
  }
  for (cathode = 0; cathode <3; cathode = cathode+1){
    pinMode (cathodePins[cathode], OUTPUT); // overkill method, thinking ahead to next project tho
    digitalWrite (cathodePins[cathode], LOW);
  }
}
void loop(){
  // could do this as for:next loop too, 'left as an exercise for the reader'
  // layer 1
  digitalWrite(cathodePins[2], LOW);  // turn off prior layer
  digitalWrite (cathodePins[0], HIGH); // turn on this layer
  for (LED =0; LED<9; LED=LED+1){ // loop thru the LEDs of rowx
    analogWrite (rowPins[LED], layer1[LED]); // 
    delayMicroseconds(1500); // 24 'frames'/second = 41.6mS, have 27 LEDs, so ontime/LED = 1.5mS
    // probably need a better way to do this for longer on time
    // as PWM switches state at ~490 Hz rate & 24*27 = 648
  }
  // layer 2
  digitalWrite(cathodePins[0], LOW);
  digitalWrite (cathodePins[1], HIGH);
  for (LED =0; LED<9; LED=LED+1){
    analogWrite (rowPins[LED], layer2[LED]);
    delayMicroseconds(1500);
  }
  // layer 3
  digitalWrite(cathodePins[1],LOW);
  digitalWrite (cathodePins[2], HIGH);
  for (LED =0; LED<9; LED=LED+1){
    analogWrite (rowPins[LED], layer3[LED]);
    delayMicroseconds(1500);
  }
  // add some code to update the PWM values
}

(compiled & autoformatted)
I’m thinking now, to get longer on-time per LED, turn on 3 LEDs at a time.
Then could leave PWM on for 4.6mS per ‘set’
If use 3 Cathode drivers like this,
you could see how 3 pins at a time could be on in just 9 patterns:
Row1 Row2 Row3
a1/c1, a7/c2, a4/c3
a2/c1, a8/c2, a5/c3
a3/c1, a9/c2, a6/c3
a4/c2, a1/c3, a7/c1
a5/c2, a2/c3, a8/c1
a6/c2, a3/c3, a9/c1
a7/c3, a4/c1, a1/c2
a8/c3, a4/c1, a2/c2
a9/c3, a4/c1, a3/c2