I have made an LED cube that is a 3x3x3 design and was wondering if there is way to make a function in the Arduino IDE where each the layers of LEDs can be represented by a list with 1 being on and 0 being off:
{1, 0, 1, 0, 1, 0, 0, 1, 0}
with the first number of the list being the first column, then the second column, etc. and the same for the rows which would be something like {0, 1, 0}
. Does this make sense? If so, is there an idea for a function that could take these inputs and transform them into digitalWrite outputs? I am using an Arduino Nano for this, with pins 2, 3, 4, 5, 6, 7, 8, 9, and 11 used for the columns with A0, A1, and A2 being the rows of the cube.
1 Answer
Well, learning bit manipulations and using three uint16_t
(as 9 bits won't fit into uint8_t
) to store state for a whole cube is much better. Then you hust have to setup timer ISR
and each time it fires just display one "floor". The multiplexing can be done even in loop, but it's usualy flickering as you can't do almost perfect timing as in the ISR
.
And for example, I was using two 2x4x4
segments to build up 4x4x4
cube and single MAX7219
to drive it, so I don't have to handle whole multiplexing and so.
My another aproach was using individually addressable LEDs like WS2812B
, so I needed only one pin to drive it all. Or by using ARM
and DMA
transfers, I could drive 8 or 16 lines simultaneously.