Is this the good way or not?

this might be a stupid question from me, but I'm a complete newbie here. Been playing around with my Arduino for a week and I've build a simple 2x2x2 cube today which is working fine. But I have a few questions. Each level is made by connecting the cathodes and this is connected by a resistor (330ohm) to the Arduino. Each column (anodes) is straight connected to an Arduino port

Can I use the same structure for a 3x3x3 cube or bigger ones (maybe changing the resistor size)? Or does this 'project' needs transistors to drive the layers or can I just continues using resistors without harming the Arduino? I know bigger ones need shift registers, but by these I can also control the state of the layer.

I am a complete disaster concerned electricty :blush: , so forgive me this stupid question

int level1 = 2;
int level2 = 3;
int c1 = 8;
int c2 = 9;
int c3 = 10;
int c4 = 11;


void setup() 
{  
pinMode(level1, OUTPUT);  
pinMode(level2, OUTPUT);  
pinMode(c1, OUTPUT);  
pinMode(c2, OUTPUT);  
pinMode(c3, OUTPUT);  
pinMode(c4, OUTPUT);
}

void loop() 
{    
digitalWrite(level2, LOW);  digitalWrite(level1, LOW);    
digitalWrite(c1, HIGH);  digitalWrite(c2, LOW);  digitalWrite(c3, LOW); digitalWrite(c4, LOW); delay(100); 

digitalWrite(level2, LOW);  digitalWrite(level1, LOW);    
digitalWrite(c1, LOW);  digitalWrite(c2, HIGH);  digitalWrite(c3, LOW); digitalWrite(c4, LOW); delay(100); 

digitalWrite(level2, LOW);  digitalWrite(level1, LOW);    
digitalWrite(c1, LOW);  digitalWrite(c2, LOW);  digitalWrite(c3, HIGH); digitalWrite(c4, LOW); delay(100);

digitalWrite(level2, LOW);  digitalWrite(level1, LOW);    
digitalWrite(c1, LOW);  digitalWrite(c2, LOW);  digitalWrite(c3, LOW); digitalWrite(c4, HIGH); delay(100);
}

When you common a set N of LEDs like this for multiplexing the common connection will, worst case, take N times the current of an individual LED.

If N=2 its not too hard to run without endagering the Arduino pin current safe limits, if you set the individual LED current at 15mA, then two will take 30mA which is OK.

If N=8 then its much less likely to work if you want decent brightness.

If you are careful to drive only one LED of a set at a time then this isn't a constraint, but that's rather limiting and it means a software error can lead to hardware being overloaded...

So yes with bigger LED arrays being multiplexed its usual to use a transistor to drive the common point of multiple LEDs.

The alternative is sizing the resistors to prevent overloading the pins, but then you get a dim display.

Note that there is also a limit to the total current sourced or sunk from all the Arduino pins (the datasheet for the chip has the full information). 40mA is the absolute max per pin with no other pins driven, note.