LED 3x5 cuboid with Arduino

I want to create the 3x5 led cuboid with Arduino
So I will have 3x3(9) leds in each layer and 5 layers.
The negative of each led in each layer are connected
And positive of each column are connected.
So in theory I can connect 9+5pins to arduino to drive this.

So now is the question. For basic led manipulations without multiplexing scenarios I can lit e.g. one layer at the time. But would arduino be able to lit 45 leds at the time.

if yes. you just made my day and I cancontinue with my project.

If not how would I be able to do it so it is possible.
e.g. reverse the cube so the layers would be connected to positive pins of leds and control them with shift register that gets external 5v supply? would that work
I could use the transistors but I am not sure how to select the which resistors to use so they would not overheat.
Any suggestion would be greatly appreciated.

If you want to light more than one LED at any moment, you need a transistor to drive the common to those LEDs you want to light at once, in your case, a layer.

However you have only 45 LEDs. For any number up to 64, a MAX7219 will multiplex them for you as a matrix, taking care of current control and giving excellent brightness and updated only when you wish to alter the pattern using only 3 control pins.

It makes little sense to attempt to do it any other way. You have to wire them to suit of course, and the code has to transform the actual wiring into your notional 3 by 3 by 5 co-ordinates, but not needing to code for the multiplexing makes it just so much easier.

As always, I recommend buying one of the MAX7219 matrix module kits, unassembled like this:

Better still buy a couple, assemble one with the matrix provided for practice, and wire the other one to your own array.

I have those modules however I wonder how would I connect such cube to this module.
The LED matrix is 2 dimential 8x8 so it is perfect for connecting. You actually buy this module to use with it.
How do I connect the 3x3x5 cube so that programing the behaviour of leds is easy
I could see it as the two dimentional matrix 5x9 but this would not work with MAX7219.

Supplying more information to make my dilema more clear.
The way the LED I soldered together is that at the end I have nine outgoing connections that should receive High signal to control LEDs in corresponding column and 5 outgoing connections that should receive LOW signal to control the corresponfing Layer.
I cannot really think of any way I can connect it to MAX7219 to be able to control those 45 LEDs in this setup.
If I am missing anythink can you point me in the right direction.

Here's how I see 45 LEDs being connected in a 5 layer, 3x3 cube. Not all of cube is shown, but I think enough to see the effective wiring.

MAX7219 has 8 segment outputs, and 8 common cathode outputs.
So you would have 5 layers, each with 8 LEDs; 8 segments lines to drive the 8 anode, and a digit line to drive the common cathode
Then a 6th "row" which is actually the 9th LED in each layer, with each connected to 6th row common cathode, and the anodes connected like other layers, to the Segment a-b-c-d-e lines.

The MAX7219 multiplexes at 800 Hz so any On LEDs will all look on.
Want a whole layer on?
Send data for that layer, and for the one extra LED.

digitalWrite (ssPin, LOW);
SPI.transfer (address); // 1 to 5 for row 0 to row 4
SPI.transfer (data);
digitalWrite (ssPin, HIGH);

digitalWrite (ssPin, LOW);
SPI.transfer (address); // 5 for row 4
SPI.transfer (0b00000001); // extra LED layer 0, then 0b00000010, 0b00000100, 0b00001000, and 0b00010000
digitalWrite (ssPin, HIGH);

Thank you for your reply
I am afraid this is way over my head:)

I am guessing
digitalWrite (ssPin, LOW);
enables the chip to listen for data
and
digitalWrite (ssPin, HIGH);

outputs the data that was send

Not sure I get
SPI.transfer (address); // 1 to 5 for row 0 to row 4
SPI.transfer (data);

Should I write it 5 times
e.g SPI.transfer(1);
SPI.transfer(data) ; and what should I put as data for each address

You completly lost me there:)
digitalWrite (ssPin, LOW);
SPI.transfer (address); // 5 for row 4
SPI.transfer (0b00000001); // extra LED layer 0, then 0b00000010, 0b00000100, 0b00001000, and 0b00010000
digitalWrite (ssPin, HIGH);

To make it easier for me what the code would be lit the whole first layer on?

To clarify.

Using a MAX7219, you would have to have the cube wired to match. If you have already wired the cube as layers, forget it, you cannot use the MAX7219!

digitalWrite (ssPin, LOW);
SPI.transfer (1); // 
SPI.transfer (0xff);
digitalWrite (ssPin, HIGH);

digitalWrite (ssPin, LOW);
SPI.transfer (6); // 
SPI.transfer (0b00000001); // extra LED layer 0, where the 1 goes depends on cube wiring
digitalWrite (ssPin, HIGH);

SPI.transfer() is the library that sends data to the MAX7219 at 4 MHz.
Select Sketch:Import Library: SPI to add it to your sketch.
In setup(), call it:
SPI.begin(); // default speed 4 MHZ clock, MSBFIRST, and SPI mode 0.

Then set up the 5 registers, see the datasheet for details. DisplayTest, Brightness, No Decode mode, Scan Mode, and Normal/Shutdown. Use the same format as above.

Then in loop(), change the data based on whatever you have going on and send it out.

Thanks
I think this is clear. I will play with the 8x8LED Matrix to fully understand the code behaviour
Fortunatelly I have the cube partially soldered. I am soldering 3 5x3 vertical layers and so far I soldered 2. So in the last one I will solder two columns of the layer like the others and the third column I will connect othey way around so it works as the 6th horisontal layer

Unfortunately I am stuck again.
I wrote following code just to make sure I Properly would control the LED8x8 matrix to start before I move to control the cube.

#include <SPI.h>
#define CS 7
void TransferData(uint8_t address, uint8_t value) {
  digitalWrite(CS, LOW);
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}
  

void setup() {
  pinMode(CS, OUTPUT);
  SPI.setBitOrder(MSBFIRST);
  SPI.begin();
  // Enable mode B
  TransferData(0x09, 0xFF);
  // Use lowest intensity
  TransferData(0x0A, 0x00);
  // Only scan one digit
  TransferData(0x0B, 0x00);
  // Turn on chip
  TransferData(0x0C, 0x01);

}

void loop() {
 
TransferData(1, 0b00000001);
delay(1000);
TransferData(2, 0b00000011);
delay(1000);

}

After two command in the main loop I would expect to see 00000001 in the firt row and 00001011
But instead I see just 00110000 in the first row and nothing in second
When I use LedControl.h library everthing works fine o I am 100% ure the connections are ok