I am working on an 5x5x5 RGB LED cube. The hardware now should be fine and works but i run into some troubles with the SPI and an 2D array.
In Short:
- I do have 80 bit in a register which i write out and set with spi in interupt cycles of 8kHz.
- Every cycle just light up 1 whole level of the cube by disabling/enabling the level with one of the last 5 bit of the 80bit
- the 75 other bit are for the colors. (rgb rgb rgb rgb and so on)
- to create different colors i push up to 5 bit through one led(00001 so 4 times off 1 time on. After one cube light up (all 5 levels lite up one time) the counter get increased). So i got level * 5 *10 byte
To handle this i thought about 1 2D array for each level of the cube. So if i set a coloe i can iterate over the right byte. But i noticed that if i take a 2D array it seems to flicker and if i take a regular array it does not flicker.
At the moment i got 5 LEDs at a register. So all5 get 3 lines for the color and 5 last bit for enabling the level.
Here is the interupt and how i write out the one byte i need to test it:
int i = 0; //bit angle counter
int j = 0;
ISR(TIMER1_COMPA_vect){
digitalWrite(blank_pin, HIGH);//shut down the led
//push the test byte
switch(j){
case 0:
{
SPI.transfer(led0[i]);
break;
}
case 1:
{
SPI.transfer(led1[i]);
break;
}
case 2:
{
SPI.transfer(led2[i]);
break;
}
case 3:
{
SPI.transfer(led3[i]);
break;
}
case 4:
{
SPI.transfer(led4[i]);
i++;
if(i>5)
{
i = 0;
}
break;
}
}
j++;
if(j > 5)
{
j=0;
}
// shift register to storage register
digitalWrite(latch_pin, HIGH);//to storage
digitalWrite(latch_pin, LOW);// to storage
digitalWrite(blank_pin, LOW); //enable the leds
pinMode(blank_pin, OUTPUT);//Output Enable important to do this last, so LEDs do not flash on boot up
}
In this case every LED has 5 byte for the coloring as explained above. But if i try to store everything in one array like led[5][5] and transfare it like SPI.transfer(led*[j]) it does flicker. Seems to be way slower or such.*
Can someone explain why this could be?
I start writing the code for the whole cube. At the Moment i would have 5 arrays out of 10byte for every level. Is there some other construct which i could easy do?
Regards
BennX