# Multidimensional Arrays

Hey guys,
I’ve built a 555 LED cube, and am trying to write code to control it.
Right now, my code goes:

``````int values[151] =
{
0,
1,0,0,0,1,
0,1,0,1,0,
0,0,1,0,0,
0,1,0,1,0,
1,0,0,0,1,
//End of first layer.
1,0,0,0,1,
0,1,0,1,0,
0,0,1,0,0,
0,1,0,1,0,
1,0,0,0,1,
//end of second layer
1,0,0,0,1,
0,1,0,1,0,
0,0,1,0,0,
0,1,0,1,0,
1,0,0,0,1,
//end of third layer
1,0,0,0,1,
0,1,0,1,0,
0,0,1,0,0,
0,1,0,1,0,
1,0,0,0,1,
//end of fourth layer
1,0,0,0,1,
0,1,0,1,0,
0,0,1,0,0,
0,1,0,1,0,
1,0,0,0,1,
//end of fifth layer
1,0,0,0,1,
0,1,0,1,0,
0,0,1,0,0,
0,1,0,1,0,
1,0,0,0,1
};

void setup()
{

for (int i=21; i <= 52; i++)
{
pinMode(i,OUTPUT);
}
}

void loop()
{

for (int z = 0; z<=5; z++)
{

for (int i = 48; i <=52; i++)
{
digitalWrite(i,HIGH);
}
digitalWrite(47+z,LOW);

for (int i=0; i <= 25; i++)
{

if (values[i+z*25]== 1)
{
digitalWrite(i+21,HIGH);

}
if (values[i+z*25]==0)
{
digitalWrite(i+21,LOW);

}

}
delay(1);

}
}
``````

Basically, it loads a huge array of on/off values, then uses them to control the LED’s.

I want to modify the code to take animations, but I keep getting errors - help?

but I keep getting errors

If you don't say what errors it will be difficult to help ;)

int values[151] defines 6 layers for a 5x5x5 cube why?

Why don't you define the array itself multidimensional: int values[5][5][5]; // uses 250 bytes

as you only store one bit in every int better make the type uint8_t (byte) uint8_t values[5][5][5] ; // uses 125 bytes

or even use one byte as an array [0..7] uint8_t values[5][5]; // uses 25 bytes

OK, you need bitoperators to get/set but these are available - http://www.arduino.cc/en/Reference/BitSet

It'd be helpful to look in playground first: http://arduino.cc/playground/Main/InterfacingWithHardware#Output "cube"