hey, im fishing for some ideas on how to code my cube! i have

hey,

im fishing for some ideas on how to code my cube!

i have the individual 3x3 segments wired up as below. the below setup allows me to easily fold into a cube shape.

my outcome would be to have (e.g.) pixel 4 lit, and to increase in the x direction, would be 4, 5, 12, 13, 14, 28, 31, 34, 37, 40, 43, 3,
y, would be 4, 1, 43, 42, 41, 34, 31, 28, 14, 13, 12, 5

at the moment its kind of hard coded, so… if direction==x, and pos==4 and then next number is 5… but this is turning out to be a massive undertaking… for every 54 numbers, i have an x, y, z leading to many many many manual adjustments…

just after some thought directions.

2dd50be943ab3a1ce2434abd9ba66ad2.png

Maybe you could figure out a lookup table for each led on a polar projection? That might be hard to animate around more than one axis, though.

Your concept of x and y existing on the cube surface itself might be problematic, since as you move around the three faces of a corner your x and y orientation would switch places, and in different signs depending on whether you went clockwise or counter…

Or treat the cube as a volume and map voxels to the face(s) they touch?

I would suggest you use x y z
Where LEDs I = x +y.3 +z. 9

Where z is your Face number Coordinate

Array lookups make everything simpler. They also let you wire the cube in a much shorter path.

If you set up an array so that you access it as leds[faceCoord][x][y], then you only need to generate the set of coordinates once (which, for a small cube like this, can be faster than defining a formula to derive the same information).

Have a look at this spreadsheet for an example of how I’d wire up the same cube:

ok, just wanted to update a little.

after a few extended hours of problem solving i have got a solution that is configurable and working.

int matrix54[9][12] = {
{ 54, 54, 54, 54, 54, 54, 42, 43, 44, 51, 52, 53 },
{ 54, 54, 54, 54, 54, 54, 39, 40, 41, 48, 49, 50 },
{ 54, 54, 54, 54, 54, 54, 36, 37, 38, 45, 46, 47 },
{ 54, 54, 54, 24, 25, 26, 33, 34, 35, 54, 54, 54 },
{ 54, 54, 54, 21, 22, 23, 30, 31, 32, 54, 54, 54 },
{ 54, 54, 54, 18, 19, 20, 27, 28, 29, 54, 54, 54 },
{ 6, 7, 8, 15, 16, 17, 54, 54, 54, 54, 54, 54 },
{ 3, 4, 5, 12, 13, 14, 54, 54, 54, 54, 54, 54 },
{ 0, 1, 2, 9, 10, 11, 54, 54, 54, 54, 54, 54 }
};

so whilst this looks messy, its the pattern shown as in the picture, although reversed. the leds are wired from the back, but then coded to the front, but the concept is the same.

instead of trying to work out how to link 6 x 3x3 grids, and then using weird maths and lots of if statements to work out the top of 1 side, to the bottom of another, i made the matrix as 1 large piece, 4x 3x3 grids across, and 3x 3x3 tall.

then all the grid spaces that are not used are filled with the address 54 (the length of the strip is 54 leds [0-53 are leds, 54 is the non-existant led at the end]

i can now use leds[matrix54[posY][posX] to specify an x and y position to light a specific led

with a strange, but welcomed result, that when trying to light led 54, there is no time loss? i was expecting that if light the leds in sequence, x, x+1, x+2, x+3, x+4 etc, then when the leds hit the 54’s there would be pauses in the light, but it doesn’t respond like that.

also, if i need to tweak the specific twists and turns of the cube when folded up, i can change a few numbers and all works out!