You are on page 1of 22


The 8x8x8 RGB LED Cube
by Kevin Darrah
V7 01/24/2013
Not a professional LED cube builder, this is how I did it, and this is my cube
#include <SPI.h>// SPI Library used to clock data out to the shift registers
#define latch_pin 2// can use any pin you want to latch the shift registers
#define blank_pin 4// same, can use any pin you want for this, just make sure
you pull up via a 1k to 5V
#define data_pin 11// used by SPI, must be pin 11
#define clock_pin 13// used by SPI, must be 13
//These variables are used by multiplexing and Bit Angle Modulation Code
int shift_out;//used in the code a lot in for(i= type loops
byte anode[8];//byte to write to the anode shift register, 8 of them, shifting
the ON level in each byte in the array
//This is how the brightness for every LED is stored,
//Each LED only needs a 'bit' to know if it should be ON or OFF, so 64 Bytes
gives you 512 bits= 512 LEDs
//Since we are modulating the LEDs, using 4 bit resolution, each color has 4
arrays containing 64 bits each
byte red0[64], red1[64], red2[64], red3[64];
byte blue0[64], blue1[64], blue2[64], blue3[64];
byte green0[64], green1[64], green2[64], green3[64];
//notice how more resolution will eat up more of your precious RAM
int level=0;//keeps track of which level we are shifting data to
int anodelevel=0;//this increments through the anode levels
int BAM_Bit, BAM_Counter=0; // Bit Angle Modulation variables to keep track of
//These variables can be used for other things
unsigned long start;//for a millis timer to cycle through the animations
void setup(){
SPI.setBitOrder(MSBFIRST);//Most Significant Bit First
SPI.setDataMode(SPI_MODE0);// Mode 0 Rising edge of data, keep clock low
SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz
//Serial.begin(115200);// if you need it?

noInterrupts();// kill interrupts until everybody is set up
//We use Timer 1 to refresh the cube
TCCR1A = B00000000;//Register A all 0's since we're not toggling any pins
TCCR1B = B00001011;//bit 3 set to place in CTC mode, will call an interrupt on
a counter match
//bits 0 and 1 are set to divide the clock by 64, so 16MHz/64=250kHz
TIMSK1 = B00000010;//bit 1 set to call the interrupt on an OCR1A match
OCR1A=30; // you can play with this, but I set it to 30, which means:
//our clock runs at 250kHz, which is 1/250kHz = 4us
//with OCR1A set to 30, this means the interrupt will be called every
// which gives a multiplex frequency of about 8kHz
// here I just set up the anode array, this is what's written to the anode
shift register, to enable each level
// don't hate on how I assigned the values to this register! haha
//finally set up the Outputs
pinMode(latch_pin, OUTPUT);//Latch
pinMode(data_pin, OUTPUT);//MOSI DATA
pinMode(clock_pin, OUTPUT);//SPI Clock
pinMode(blank_pin, OUTPUT);//Output Enable important to do this last, so LEDs
do not flash on boot up
SPI.begin();//start up the SPI library
interrupts();//let the show begin, this lets the multiplexing start
}//***end setup***end setup***end setup***end setup***end setup***end
setup***end setup***end setup***end setup***end setup
void loop(){//***start loop***start loop***start loop***start loop***start
loop***start loop***start loop***start loop***start loop
//Each animation located in a sub routine
// To control an LED, you simply:
// LED(level you want 0-7, row you want 0-7, column you want 0-7, red
brighness 0-15, green brighness 0-15, blue brighness 0-15);


// The first level LEDs are first in the sequence. if(green<0) green=0. int column. if(blue>15) blue=15. if(level>7) level=7. row 4. and 0 or 15 for brightness if(level<0) level=0. column 5.. so when we write to level 2. if(column>7) column=7. byte green. if(blue<0) blue=0. int whichbyte = int(((level*64)+(row*8)+column)/8). and so on //the (level*64) is what indexes the level's starting place. with the inputs for the LED location and its R G and B brightness levels // First. if(red<0) red=0. byte red. then 2nd level. if(column<0) column=0. //so if you looked down on the cube. and only looked at the bottom level // 00 01 02 03 04 05 06 07 . if(row<0) row=0. //There are 512 LEDs in the cube. then third. row 0. check and make sure nothing went beyond the limits. just clamp things at either 0 or 7 for location.}//***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop void LED(int level.. if(green>15) green=15. byte blue){ //****LED Routine****LED Routine****LED Routine****LED Routine //This is where it all starts //This routine is how LEDs are updated. level 1 are LEDs 64-127. so level 0 are LEDs 0-63. if(red>15) red=15. and so on //The column counts left to right 0-7 and the row is back to front 0-7 //This means that if you had level 0. that needs to be translated into a number from 0 to 511 //This looks confusing. the bottom back row would count from 0-7. I know. if(row>7) row=7. int row.

bitWrite(red2[whichbyte]. 511/8 = 63. 2)). but here we don't divide by 8. so each color contains x4 64 byte arrays. Notice how each line is a bitWrite. bitRead(red. wholebyte-(8*whichbyte). wholebyte-(8*whichbyte). 1)). 1)). 2)). bitWrite(green1[whichbyte]. 7.// // // // // // // 08 16 24 32 40 48 56 09 17 25 33 41 49 57 10 18 26 34 42 50 58 11 19 27 35 43 51 59 12 20 28 36 44 52 60 13 21 29 37 45 53 61 14 22 30 38 46 54 62 15 23 31 39 47 55 63 //Then. if we wanted to write to the LED to the last LED in the cube.. and take the int of it so. 2)). 7 // giving (7*64)+(7*8)=7 = 511. bitWrite(green0[whichbyte]. wholebyte-(8*whichbyte). bitWrite(blue2[whichbyte]. explanation below: bitWrite(red0[whichbyte]. //bitWrite(the byte you want to write to. bitWrite(blue3[whichbyte]. allowing you to use level. bitRead(red. we would write a 7. wholebyte-(8*whichbyte). bitRead(blue. wholebyte-(8*whichbyte). bitWrite(green3[whichbyte]. 3)). the bit of the byte to write. which is right. 3)). bitRead(green. and take the integ7er of it. wholebyte-(8*whichbyte).well. let's take an example. 0)). bitWrite(red1[whichbyte].. what about the divide by 8 in there? //. wholebyte-(8*whichbyte). column //Now. //This will all make sense in a sec //This is 4 bit color resolution. bitRead(blue. bitRead(blue. wholebyte-(8*whichbyte). but now let's divide it by 8. so we get the LED number 0-511 int wholebyte=(level*64)+(row*8)+column. bitRead(red. which is. which is right since this is the last LED // This next variable is the same thing as before. 3)).875. bitRead(green. bitRead(red. bitRead(green. so we know which byte. and we have 64 bytes in memory for all 512 bits needed for each LED. //this is the last byte in the array. 1)). since each LED represents a bit in //an array of 64 bytes. and the 0 or 1 you want to write) //This means that the 'whichbyte' is the byte from 0-63 in which the bit corresponding to the LED from 0-511 //Is making sense now why we did that? taking a value from 0-511 and converting it to a value from 0-63. so //we divide the number we just found by 8. bitRead(blue. 0)). bitWrite(green2[whichbyte]. the top right of the grid above would start at 64 //The reason for doing this. //Are you now more confused? You shouldn't be! It's starting to make sense now. bitRead(green. 0)). if you incremented the level. is so you don't have to memorize a number for each LED. wholebyte-(8*whichbyte). row. we get 63. we have 8 bits per byte. bitWrite(blue1[whichbyte]. wholebyte-(8*whichbyte). . bitWrite(blue0[whichbyte]. wholebyte-(8*whichbyte). bitWrite(red3[whichbyte]. that bit is located //confused? that's ok. wholebyte-(8*whichbyte).

rr.//Latch pin HIGH PORTD &= 0<<latch_pin. fty. gg. }//***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END //*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE //*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE //*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE //*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE ). gg. fty-1. send out the anode level byte PORTD |= 1<<latch_pin. //if you wrote a 15 to RED.//Latch pin LOW PORTD &= 0<<blank_pin.transfer(anode[anodelevel]). fty. fty. rr. gg. so if you took 505-(8*63). LED(ftx-1. LED(ftx. so go back level=0.//Then next line is which bit 'wholebyte-(8*whichbyte)' //This is simply taking the LED's value of 0-511 and subracting it from the BYTE its bit was located in times 8 //Think about it. fty+1. LED(ftx+1. ftz-1. ftz. byte 63 will contain LEDs from 504 to 511. bb). ftz. ftz. rr. bb). rr. rr. gg. which is used to shift out data. and BLUE //hopefully this all makes some sense? }//****LED routine end****LED routine end****LED routine end****LED routine end****LED routine end****LED routine end****LED routine end ISR(TIMER1_COMPA_vect){//***MultiPlex BAM***MultiPlex BAM***MultiPlex }//switch_case SPI. GREEN. this means you just sent out all 63 bytes. LED(ftx. bb). LED(ftx. . since the next level woudl be the next 8 bytes in the arrays if(anodelevel==8)//go back to 0 if max is reached anodelevel=0. you still have to do the bitRead of the brightness 0-15 you are trying to write. bb). gg. bb).//finally. meaning that. LED(ftx.//Blank pin LOW to turn on the LEDs with the new data anodelevel++. bb). all 4 arrays for that LED would have a 1 for that bit. fty. ftz. rr.//inrement the anode level level = level+8. meaning it will be on 100% //This is why the four arrays read 0-4 of the value entered in for RED.//increment the level variable by 8. you get a 1. //LED number 505 is is located in bit 1 of byte 63 in the array //is that it? No. ftz+1. gg. if(level==64)//if you hit 64 on level.

ftzo=ftz. if(direct==0) fx= fx+fxm.} if(fty>7){ fty=7. fzm=-1.} }//while for(xxx=0. 0. ftxm=-1. if(direct==1) fy= fy+fym. fym=-1. zzz. if(direct==2) ftz= ftz+ftzm. ftym=-1. ftzm=-1. zzz<8. 0. fzm=1.} if(fz>7){ fz=7.} if(fy>7){ fy=7.} if(fz<0){ fz=0. if(direct==1) fty= fty+ftym. ftym=1. ftzm=1. yyy. if(direct==0) ftx= ftx+ftxm.} if(fy<0){ fy=0. fxm=-1. fzo=fz. ftxm=1.} if(ftz<0){ ftz=0.} if(ftx>7){ ftx=7. zzz++){ LED(xxx.delay(10). xxx<8.} if(ftz>7){ ftz=7. fyo=fy. fxo=fx.} direct=random(3). if(fx<0){ fx=0. ftxo=ftx. 0). if(direct==2) fz= fz+fzm. yyy<8. fxm=1.} if(fty<0){ fty=0.} if(fx>7){ fx=7. }}} . fym=1. direct=random(3). ftyo=fty. yyy++){ for(zzz=0. xxx++){ for(yyy=0. if(ftx<0){ ftx=0.

10. if(z[addr]>=7) LED(z[addr]. addr<leds. z[64]. xold[addr]. 11). y[addr]. y[addr]. 15. y[addr]. x[addr]. yold[64]. y[addr]. 10. 0. x[addr]. 5. 15. y[addr]. 1. x[addr]. y[addr]. 0. y[addr]. 15. z[addr]=random(8). y[addr]. 1). 15). 0). addr++){ LED(zold[addr]. } start=millis(). if(z[addr]==1) LED(z[addr]. y[64]. 0. y[addr]. if(z[addr]==3) LED(z[addr]. 0. 0). if(z[addr]==4) LED(z[addr]. 0. addr. bright=1. addr++){ LED(zold[addr]. 0. y[addr]. addr<leds. 0). 0. if(z[addr]>=7) LED(z[addr]. 0. y[addr]=random(8). 10. 12). ledcolor. 3. if(ledcolor<200){ for(addr=0. xx[addr]=random(16). zold[64]. 0. x[addr]. 9). 0. x[addr]. addr++) //LED(zold[addr]. yold[addr]. addr++){ x[addr]=random(8). x[addr]. x[addr]. x[addr]. 15). while(millis()-start<20000){ //wipe_out(). 10. x[addr]. x[addr]. //for(addr=0. addr<64.}//wipeout void rainVersionTwo() {//****rainVersionTwo****rainVersionTwo****rainVersionTwo****rainVersionTwo*** *rainVersionTwo int x[64]. 0). }}//200 if(ledcolor>=200&&ledcolor<300){ for(addr=0. for(addr=0. int xx[64]. x[addr]. 1. zz[64]. 15. 0). if(z[addr]==5) LED(z[addr]. y[addr]. 0. if(z[addr]<=0) LED(z[addr]. 10). yy[64]. if(z[addr]==2) LED(z[addr]. . if(z[addr]==6) LED(z[addr]. 0). 0. colowheel. if(z[addr]==5) LED(z[addr]. 5. 10). xold[addr]. xold[64]. slowdown. xold[addr]. 2. 0. yold[addr]. yold[addr]. addr<leds. 0). zz[addr]=random(16). leds=64. if(z[addr]==4) LED(z[addr]. 0. if(z[addr]==6) LED(z[addr]. yy[addr]=random(16). 10. 0. y[addr]. x[addr].

if(ledcolor>=300) ledcolor=0. } delay(15). 0. if(z[addr]==2) LED(z[addr]. if(z[addr]==1) LED(z[addr]. addr<leds. //for(addr=0. zold[addr]=z[addr]. y[addr]. 0). 0). addr<leds. x[addr]. 15. y[addr]. x[addr]. for(addr=0. y[addr]=random(8). 10. y[addr]. addr++){ xold[addr]=x[addr]. 0). 12. x[addr]. if(z[addr]<=0) LED(z[addr]. 1. addr<leds. //if(bitRead(z[addr]. yold[addr]=y[addr]. if(select==0){ xx[addr]=0. addr++) //LED(z[addr]. //zz[addr]=0. addr++){ //slowdown = random(2). 0). int select=random(3). yy[addr]=random(16).0)) z[addr] = z[addr]-1. for(addr=0. }}//300 y[addr]. //yy[addr]=0. zz[addr]=0. x[addr].if(z[addr]==3) LED(z[addr]. 15. y[addr]. if(z[addr]<random(-100. 0.0)){ x[addr]=random(8). } if(select==1){ xx[addr]=random(16). zz[addr]=random(16). yy[addr]=random(16). // x[addr] = x[addr]+1. . 0. if(ledcolor>=300&&ledcolor<400){ } if(ledcolor>=500&&ledcolor<600){ } ledcolor++. 0). 0. 0. // y[addr] = y[addr]+1. x[addr].

folderaddr[3]=-4. folderaddr[1]=-6. folderaddr[4]=-3.} if(select==2){ xx[addr]=random(16). oldpullback[16]. front=0. xx<8. for(xx=0. }//-check }//add }//while }//rainv2 void folder() {//****folder****folder****folder****folder****folder****folder****folder****f older****folder int xx. } start=millis(). back=0. xx<8. 0). 0. folderaddr[6]=-1. yy<8. int bot=0. yy-pullback[yy]. } z[addr]=7. LED_Old[16]. yy. side_select. ranx=random(16). right=0. xx++){ LED(7-LED_Old[yy].xx . state=0. zz[addr]=random(16). folderaddr[0]=-7. folderaddr[7]=0. rany. folderaddr[2]=-5. 0. LED(7-folderaddr[yy]. ranselect. yy-oldpullback[yy].//backorfront 7 for back 0 for front int folderaddr[16]. yy++){ for(xx=0.xx . xx++){ oldpullback[xx]=0. while(millis()-start<10000){ if(top==1){ if(side==0){ //top to left-side for(yy=0. pullback[16]. left=0. yy[addr]=0. zz. ranz). }}} if(side==2){ . pullback[xx]=0. ranz=random(16). rany=random(16). side=0. top=1. backorfront=7. folderaddr[5]=-2. ranx.

xx<8. ranz). ranz).xx . }}} if(side==3){ //top-side to front-side for(yy=0. 0. ranx.7-LED_Old[yy].xx . xx<8. 0. yy+oldpullback[yy]. yy<8. LED(7-folderaddr[7-yy]. yy+pullback[yy]. }}} if(side==3){ //right-side to front-side for(yy=0. yy<8. yy++){ for(xx=0. xx. ranz). xx<8. }}} if(side==1){ //top-side to right for(yy=0. xx<8. xx++){ LED(yy+oldpullback[7-yy]. rany. yy-pullback[yy]. xx++){ LED(7-LED_Old[7-yy]. rany. yy++){ for(xx=0. 0). yy<8. yy+oldpullback[yy]. xx. 0. rany. }}} }//right if(left==1){ if(side==4){ //left-side to top . yy<8. 0. yy+pullback[yy]. LED(7-folderaddr[7-yy]. ranz). 7-LED_Old[7-yy].7-LED_Old[7-yy]. yy+pullback[yy]. ranx. ranz). xx++){ LED(xx. yy++){ for(xx=0. xx++){ LED(yy-oldpullback[yy]. ranx. LED(xx. ranx. 0. rany. 0. yy-oldpullback[yy]. yy<8. 0). yy++){ for(xx=0.xx . xx<8. 0. rany. LED( yy+pullback[7-yy]. }}} if(side==5){ //right-side to bottom for(yy=0. 0).7-folderaddr[7-yy]. rany. LED(7-folderaddr[yy]. 0. xx<8. xx<8. ranx. LED(xx. xx++){ LED(7-LED_Old[7-yy].yy+oldpullback[yy].xx . yy-pullback[yy]. ranx.yy-oldpullback[yy]. 0. 0.xx . 7-LED_Old[yy]. 0. 0. xx. 0. 0.xx . yy++){ for(xx=0. 0). rany. 0). LED( yy-pullback[yy]. yy++){ for(xx=0. 0). yy<8. yy++){ for(xx=0.7-folderaddr[7-yy]. }}} }//top if(right==1){ if(side==4){ //right-side to top for(yy=0. xx.//top to back-side for(yy=0. 0). yy<8. xx++){ LED(xx.7-folderaddr[yy]. ranz). ranx. xx++){ LED(7-LED_Old[yy]. ranz). }}} if(side==2){ //right-side to back-side for(yy=0.7-folderaddr[yy].

0). xx++){ LED(xx. LED( yy+pullback[yy]. ranz). yy++){ for(xx=0. xx. 0). LED_Old[7-yy]. yy<8. LED(xx. ranx.LED_Old[7-yy] . 0. }}} if(side==2){ //left-side to back-side LED(yy+oldpullback[yy]. xx++){ LED(LED_Old[7-yy].LED_Old[yy] . }}} if(side==3){ //bottom to front-side for(yy=0.LED_Old[7-yy]. yy++){ for(xx=0. xx++){ LED(LED_Old[yy]. }}} if(side==2){ //bottom to back-side for(yy=0.folderaddr[7-yy]. yy++){ for(xx=0. xx. yy++){ for(xx=0. 0). xx<8. yy-pullback[yy]. ranx. xx<8. yy+oldpullback[yy]. 0. LED(folderaddr[7-yy].for(yy=0.xx. 0. rany. xx<8. 0). 0. 0. yy<8. }}} if(side==0){ //bottom to left-side for(yy=0. LED(xx. 0. yy-pullback[yy]. }}} }//back if(bot==1){ if(side==1){ // bottom-side to right-side for(yy=0. LED( yy+pullback[yy].yy+oldpullback[yy]. ranx. 0. 0. 0).xx. xx<8. ranx. yy++){ for(xx=0.LED_Old[yy]. LED( yy-pullback[yy]. }}} if(side==5){ // back-side to bottom for(yy=0. xx<8. 0. ranz).xx . yy++){ for(xx=0. yy++){ .xx.xx .xx . ranz). yy-oldpullback[yy]. yy+pullback[yy]. yy<8. 0. 0). 0. ranz). }}} if(side==3){ //left-side to front-side for(yy=0. xx++){ LED(yy+oldpullback[yy]. xx++){ LED(yy-oldpullback[yy]. xx<8. xx++){ LED(xx. yy<8.xx. 0. xx. xx. rany. rany. 0.xx . xx<8.folderaddr[7-yy]. rany. yy+pullback[yy]. ranx. }}}//state1 if(side==0){ //back-side to left-side for(yy=0. 0. ranx. ranx. yy<8. rany. ranz). yy<8. 0).folderaddr[yy]. rany.folderaddr[7-yy] . LED(folderaddr[7-yy]. ranx. 0. xx++){ LED(LED_Old[7-yy]. yy<8.folderaddr[yy] . 0. ranz). LED(folderaddr[yy]. yy+oldpullback[yy]. yy-oldpullback[yy]. ranz). ranz). rany. yy+pullback[yy]. yy<8. yy++){ for(xx=0. 0). rany.

0.7-LED_Old[7-yy]. rany. 0). 0). xx++){ LED(yy-oldpullback[yy].7-folderaddr[7-yy] . rany. yy<8.xx. 0. yy<8. 0.// DELAY for(xx=0.xx . 0). yy-pullback[yy]. 0).7-folderaddr[yy]. oldpullback[xx]=pullback[xx]. ranz). xx++){ LED(yy+oldpullback[yy].xx. if(pullback[7]==8){//finished with fold DELAY . yy<8. yy<8. ranx. ranz). rany.xx. xx++){ LED(xx. yy-pullback[yy]. 0). 0. ranz). yy-oldpullback[yy]. zz<8. xx<8.7-LED_Old[yy]. }}} }//front delay(5). ranx. yy++){ for(xx=0. xx<8. 0. 0. yy++){ for(xx=0. xx++){ LED(LED_Old[yy]. for(zz=0. 0. 0. ranz). xx<8. LED(xx. yy++){ for(xx=0. 0.7-LED_Old[yy] . yy-oldpullback[yy].xx. xx++){ LED(xx. }}} }//bot if(front==1){ if(side==0){ //front-side to left-side for(yy=0. yy+pullback[yy]. LED(folderaddr[yy]. zz++) pullback[zz] = pullback[zz]+1.7-folderaddr[7-yy]. ranx. }}} if(side==4){ // front-side to top-side for(yy=0. LED(xx.xx .7-folderaddr[yy] . }}} if(side==1){ //front-side to right-side for(yy=0. yy+oldpullback[yy]. }}} if(side==5){ // front-side to bottom for(yy=0. xx<8.7-LED_Old[7-yy] .for(xx=0. } DELAY if(folderaddr[7]==7){ // pullback=8. rany. 0. yy++){ for(xx=0. rany. xx<8. ranx. xx++){ LED_Old[xx]=folderaddr[xx]. LED( yy+pullback[yy]. ranx. xx<8. ranz). LED( yy-pullback[yy].

ranz=random(1. . if(side_select==0) side=2.16). if(side_select==0) side=5.} if(ranselect==2){ ranx=random(1.16).16). if(side_select==0) side=0.16).} side_select=random(3). rany=0. if(side==0){//top to left left=1. if(ranselect==0){ ranx=0. ranselect= random(3). //if(state==4) //state=0. if(side_select==2) side=5.} if(ranselect==1){ ranx=random(1. } } else//top if(bot==1){// BOTTOM bot=0. ranz=random(1. rany=random(1. //state++.delay(10).16). if(side_select==2) side=3. //if(side_select==3) side=4. if(side_select==1) side=1. if(top==1){// TOP top=0. if(side==0){//bot to left left=1. if(side_select==1) side=1. if(side_select==1) side=3. rany=random(1. //if(side_select==3) side=4. if(side_select==2) side=5. } else if(side==3){//top to front front=1. if(side_select==0) side=0.} else if(side==1){//top to right right=1.16). } else if(side==2){//top to back back=1. if(side_select==2) side=5. //if(side_select==3) side=4. ranz=0. if(side_select==0) side=2. if(side_select==1) side=2. //if(side_select==2) side=4.

} else if(side==5){//front to bot bot=1. if(side_select==2) side=4. if(side_select==1) side=1. if(side_select==1) side=2. if(side_select==2) side=4. if(side_select==0) side=1.} else if(side==2){//bot to back back=1. //if(side_select==2) side=3.} else if(side==3){//left to front front=1. if(side_select==1) side=5.} } else//bot if(right==1){// right=0. //if(side_select==0) side=0. if(side_select==0) side=0. //if(side_select==0) side=5. //if(side_select==0) side=0. if(side_select==1) side=0. if(side==4){//right to top top=1. //if(side_select==1) side=3. if(side_select==2) side=4. if( if(side_select==2) side=1. if(side_select==1) side=1. if(side_select==2) side=4. //if(side_select==3) side=5. } else if(side==1){//bot to right right=1. if(side_select==0) side=2. if(side_select==0) side=1. //if(side_select==2) side=5. if(side_select==2) side=4. if(side_select==1) side=5. if(side_select==0) side=2.} else if(side==3){//bot to front front=1. if(side_select==0) side=0.} else if(side==2){//left to back back=1. //if(side_select==2) side=5. if(side==4){//front to top top=1. if(side_select==1) side=3. if(side_select==2) side=1.if(side_select==1) side=3. if(side_select==2) side=4. if(side_select==2) side=1. if(side_select==0) side=0. if(side_select==0) side=2.} else RIGHT front .} } else//bot if(front==1){// front=0.

xx++){ oldpullback[xx]=0. if(side_select==2) side=4. if(side==4){//back to top top=1. yy<8. folderaddr[3]=-5. folderaddr[6]=-2. if(side_select==0) side=0. 0. // if(side_select==1) side=3. if(side_select==2) side=4. // if(side_select==1) side=3. . if(side_select==2) side=4. pullback[xx]=0. folderaddr[4]=-4. if(side_select==0) side=3. if(side_select==1) side=5. folderaddr[1]=-7.if(side==0){//front to left left=1. if(side_select==1) side=0. if(side_select==0) side=2. //if(side_select==1) side=2.} else if(side==1){//front to right right=1. if(side_select==0) side=3. 0).} else if(side==1){//back to right right=1. if(side_select==2) side=1. //if(side_select==0) side=2.} } else//bot if(back==1){// back=0. 0. if(side_select==1) side=5. for(xx=0.} else if(side==0){//back to left left=1. xx++) //LED(LED_Old[yy]. yy++) //for(xx=0. if(side_select==0) side=3. folderaddr[5]=-3. //if(side_select==0) side=2.} folderaddr[0]=-8. xx<8.} } //bot back // for(yy=0. yy-oldpullback[yy]. if(side_select==1) side=5. if(side_select==1) side=5. if(side_select==0) side=2. folderaddr[2]=-6. //if(side_select==0) side=2. if(side_select==2) side=4. xx. xx<8. if(side_select==1) side=3.} else if(side==5){//back to bot bot=1. if(side_select==2) side=1.

yy[addr]. addr<ledcount+1. zz[addr]=0. ranr. addr. zbit=1.zz[addr]).0. LED(x[addr]. ledcount=20. while(millis()-start<15000){ direct = random(3).oldz[addr]. y[50]. for(addr=1. addr++){ LED(oldx[addr]. rang. oldx[50]. z[addr]. xx[addr]=0. int xx[50]. addr++){ oldx[addr]=0. ranb. oldy[50]. oldz[50]. yy[addr]=0. ybit=1. 0.0). addr++){ oldx[addr]=x[addr]. z[addr]=0. } start=millis(). oldz[addr]=0. zz++) folderaddr[zz] = folderaddr[zz]+1. }//while }//folder void bouncyvTwo() {//****bouncyTwo****bouncyTwo****bouncyTwo****bouncyTwo****bouncyTwo****bouncy Two****bouncyTwo int wipex. addr<ledcount+1. } for(addr=1. y[addr]. direct. wipez. zz[50]. oldz[addr]=z[addr]. zz<8. addr<ledcount+1. int xbit=1.folderaddr[7]=-1. xx[addr]. int x[50]. }//pullback==7 }//folderaddr==7 if(folderaddr[7]!=7) for(zz=0. x[addr]=0. yy[50]. for(addr=0. select. y[addr]=0. oldy[addr]=0. direcTwo. z[50]. oldy[addr]=y[addr]. . wipey. oldy[addr]. } delay(20).

zz[0]=random(16). zz[0]=random(16). //if(direcTwo==1) if(direct==0) x[0]= x[0]+xbit. y[0]=0. if(direct==4) y[0]= y[0]-ybit. //wipe_out(). } if(y[0]>7){ ybit=-1. y[0]=7. if(direct==5) z[0]= z[0]-zbit.//direcTwo=random(3). } . yy[0]=random(16). xx[0]=0. x[0]=7. x[0]=0. } if(x[0]<0){ xbit=1. } if(y[0]<0){ ybit=1. //wipe_out(). xx[0]=random(16). xx[0]=0. //wipe_out(). if(x[0]>7){ xbit=-1. xx[0]=random(16). if(direct==3) x[0]= x[0]-xbit. yy[0]=random(16). //wipe_out(). yy[0]=random(16). zz[0]=0. if(direct==2) z[0]= z[0]+zbit. zz[0]=random(16). yy[0]=0. if(direct==1) y[0]= y[0]+ybit.

sinewavearray[6]=6. addr. addr>0. } }//while }//bouncyv2 void sinwaveTwo() {//*****sinewaveTwo*****sinewaveTwo*****sinewaveTwo*****sinewaveTwo*****sinewa veTwo*****sinewaveTwo int sinewavearray[8]. sinewavearray[5]=5. sinewavearray[7]=7. sinemult[3]=1. z[0]=7. sinemult[2]=1. bb=15. sinemult[5]=1. sinewavearray[2]=2. xx[addr]=xx[addr-1]. //wipe_out(). sinemult[4]=1. multi=0. sinewavearray[3]=3. yy[0]=0. sinewavearray[0]=0. subZ=-7. sinemult[7]=1. addr--){ x[addr]=x[addr-1]. sinewavearray[4]=4. xx[0]=random(16). yy[0]=random(16). sinemult[0]=1. sinewavearray[1]=1. colselect.if(z[0]>7){ zbit=-1. sinemult[1]=1. subT=7. . //wipe_out(). sinemult[8]. zz[addr]=zz[addr-1]. 2). y[addr]=y[addr-1]. zz[0]=0. int sinewavearrayOLD[8]. xx[0]=random(16). select. } for(addr=ledcount. zz[0]=random(16). sinemult[6]=1. addrt. gg=0. yy[addr]=yy[addr-1]. rr=0. z[0]=0.//random(-1. z[addr]=z[addr-1]. } if(z[0]<0){ zbit=1.

LED(sinewavearrayOLD[addr+multi*1]. rr. bb). 1. gg.} if(select==2){ rr=0. bb). bb). gg. LED(sinewavearray[addr]. 0. LED(sinewavearray[addr+multi*1]. 7. 0). 0. addr<8. gg. addr. bb=random(1. 16). 0. 7. gg. 0). bb=0. bb). 1. 16). LED(sinewavearrayOLD[addr].start=millis(). subT-addr. addr. 1. 0. addr. 0. rr. 0. addr. 0.7. 0. 16). 16). subT-addr. */ } for(addr=0. }//addr if(sinewavearray[0]==7){ select=random(3). addr<8. addr. 7. gg=random(1. bb=random(1. 0. gg=0. subT-addr. . 0). 6. addr. LED(sinewavearray[addr]. 6. gg. 0). LED(sinewavearrayOLD[addr]. subT-addr. 0. addr. subT-addr. 0. 16). 0. 0. } if(sinewavearray[addr]==0){ sinemult[addr]=1. 0. 0. 0). 0).} /* if(multi==1) multi=0. LED(sinewavearray[addr]. 0. addr. LED(sinewavearrayOLD[addr]. 0. 0). 1. 0. 16). rr. addr++){ if(sinewavearray[addr]==7){ sinemult[addr]=-1.} if(select==1){ rr=random(1. LED(sinewavearray[addr]. while(millis()-start<15000){ for(addr=0. rr. addr++){ LED(sinewavearrayOLD[addr]. gg=random(1. else multi=1. addr++){ LED(sinewavearrayOLD[addr+multi*1]. addr<7. }//} for(addr=1. bb). 0). 0. if(select==0){ rr=random(1. gg. bb). LED(sinewavearrayOLD[addr+multi*1]. LED(sinewavearrayOLD[addr+multi*1]. } sinewavearray[addr] = sinewavearray[addr] + sinemult[addr]. LED(sinewavearray[addr+multi*1]. subT-addr. rr. rr. 0.

0. yy. gg.zz<8. zz. for(xx=7.6.5. LED(sinewavearray[addr+multi*1].zz++){ } LED(xx. subT-addr. subT-addr. rany=random(16). for(xx=0. subT-addr.yy++){ for(zz=0. zz. bb). 0.xx>=0.yy++){ .xx<8. addr. } ranx=random(16). gg.xx++){ for(yy=0. }} delay(50).zz++){ LED(xx. bb=1. subT-addr. rany. gg. gg. LED(sinewavearray[addr+multi*2]. addr. while(millis()-start<100000){ swiper=random(3). 0). 0). start=millis(). rr=1. LED(sinewavearrayOLD[addr+multi*2]. rany=random(16). ranx=random(16). 0). for(xx=0. } ranx=random(16). rany). subT-addr.xx<8. 2. LED(sinewavearrayOLD[addr+multi*2]. 2. bb). rany). 0. ranx. 2. } for(addr=2.zz<8.yy<8. 5. 0. for(xx=7. rr. } int xx.yy++){ for(zz=0.yy. ranx. rany=random(16). gg.xx>=0. ranx. bb). 0. rany. rr. yy. ranx=random(16). rr. zz.zz++){ LED(xx. rr.yy<8.yy<8. 0. 0. zz. 0. }} delay(50). subT-addr. }} delay(50). gg. addr++){ LED(sinewavearrayOLD[addr+multi*2]. LED(sinewavearray[addr+multi*2]. rany=random(16). 5.zz<8. ww.xx--){ for(yy=0. 0). 5. LED(sinewavearray[addr+multi*2]. addr. LED(sinewavearray[addr+multi*2].yy<8. swiper.xx--){ for(yy=0. addr<6.yy++){ for(zz=0. 6. ranx. gg=1. 2. 0). bb). addr. 0. LED(sinewavearrayOLD[addr+multi*2]. rr.yy.LED(sinewavearray[addr+multi*1]. 0. rr.xx++){ for(yy=0. bb). bb).

zz++){ for(xx=0.ranz.zz<8. rany=random(16). zz. rany). zz.} if(select==2){ ranx=random(16). ranz. yy.yy<8. ranz. zz. }} delay(30).yy++){ for(zz=0. gg=1. while(millis()-start<10000){ swiper=random(6). }} delay(50).xx++){ for(yy=0. ranx.xx<8. zz.zz<8. rany=random(16). 0).zz++){ LED(xx.yy<8.yy. zz. }} . }} if(swiper==1){//bot to top for(xx=0. ww.yy++){//left to right for(xx=0. }} delay(30). bb=1. yy.xx<8.zz<8. start=millis().xx<8. ranz=random(16). rany).yy<8.zz++){ LED(xx. ranz=0.xx++){ for(zz=0.zz<8. ranz. if(select==0){ ranx=0. ranz=random(16). select.zz++){ LED(xx. yy. rany=0. ranx.for(zz=0.yy++){ LED(xx. rany). ranx.} if(swiper==0){ for(yy=0. select=random(3). rany .} if(select==1){ ranx=random(16). }} if(swiper==2){//back to front for(zz=0. ranx. } }//while }//color wheel void color_wheelTWO() {//*****colorWheelTwo*****colorWheelTwo*****colorWheelTwo*****colorWheelTwo*** **colorWheelTwo int xx.xx++){ for(yy=0. swiper. rr=1. rany. yy. ranx.

ranz. }} }//while }//color wheel . zz. }} if(swiper==4){//top to bot for(xx=7.zz<8. }} if(swiper==3){ for(yy=7. }} if(swiper==5){//front to back for(zz=7. ranx. ranz.zz>=0. ranx. ranx.yy++){ for(zz=0.xx<8. rany). }} delay(30). yy.xx<8.delay(30).zz++){ LED(xx. }} delay(30).xx>=0. yy. }} delay(30).yy<8.yy<8.yy--){//right to left for(xx=0. rany). zz.yy++){ LED(xx. rany). zz.zz--){ for(xx=0.yy>=0.xx++){ for(zz=0.xx--){ for(yy=0.zz++){ LED(xx. ranz.xx++){ for(yy=0.zz<8. yy.