Tuesday, June 22, 2010

explosion test clip

slightly better quality video of the explosion animation from 3dleds.com running on my cube.
http://www.youtube.com/watch?v=jlJ9fSPPUEc


For anyone attempting this for them self, I imagine if you got this far it probably isn't very hard to work out how to run these animations on your cube. If you've developed this for yourself like I have, there is no "standard" way to program these so there will no doubt be some tweaking you need to do for yourself.

For me, in my code, the entire cube is represented by a single data array:

display_array[NUM_ROWS][NUM_TLCS*16];

where NUM_ROWS and NUM_TLCS are number or rows and TLC drives respectively. 8 and 12 in my case.

All 12 TLCs are in series, the 1st 4 control RED, the next 4 green and the last 4 blue.

I also have a easy function called SET


static void set(unsigned char row, unsigned char channel, int value)
{
display_array[row][NUM_TLCS * 16 - 1 - channel] = value;
}//set



The trick is, my array is made up of 16bit "ints", however the TLCs only accept 12bit values. You can't make an array of 12bit elements, but my 12 bit values happily sit in 16 bit "ints".  Instead of trying "pack" the values into my array like some code I've seen, instead I strip the values out when it comes time to send them through the SPI module. I won't go into that here.

So, after studying the file description on the 3dleds site, I figured out that I would have to transfer the values row by row and color by color, AND frame by frame with a bit of a delay to control the speed of the animation.

All i then had to do was work out the offsets of data for each color, row and the "frame" and create loops for each. 3 colors nested inside rows, all nested inside frames. chr, chg and chb probably didn't have to be separate values, but it was easier to picture for me this way. I'm still only a novice programmer so you'll probably find this either not interesting, or already obvious.. But I like sharing so here it is:


int f; //frame
int r; //row

int chr; //chan r
int chg; //chan g
int chb; //chan b

int v; //value

int p; //position.

for (f=0;f<128;f++)
{

for(r=0;r<8;r++)
{

for (chr = 0; chr < 64; chr++)
{
p = chr+ (r*64) + (f*1536);
v = rawData[p]*15;
set(r,chr,v);
}

for (chg = 64; chg < 128; chg++)
{
p = chg+ 512-64 +(r*64) + (f*1536);
v = rawData[p]*15;
    set(r,chg,v);
}

for (chb = 128; chb < 192; chb++)
{
p = chb+ 1024-128+(r*64) + (f*1536);
v = rawData[p]*15;
    set(r,chb,v);
}

DelayMs(3);
}//for r

}//for f

1 comment:

visitor counter