BASIC LED CUBE ANIMATIONS Part-2

In this article I'm going to show you how I built some animations for the 8x8x8 LED RGB cube project

For this part I made a function call fountain water which lights up from the center of the cube, and it spills out of the cube. This animation could have many repetition loops, but since we can take the advantage to play with functions that made more simple and short in terms of line of codes. This animation contain 4 functions, one that clear the center, then one that forms the top and sides, one that will clear the leds behind and the main function. Bellow is the function that clear the center of the fountain.

void waterFountainF(int level){
     for(int j=3; j<5; j++)
       for(int k=3; k<5; k++){
          LED(level,j,k,0,0,0);
       }
}

Next is the function for the top and sides of the fountain.

void waterFountainFA(int level,int r,int g,int b){
      for(int j=0; j<1; j++)
        for(int k=0; k<8; k++){
          LED(level,j,k,r,g,b);
        }
      for(int j=7; j<8; j++)
        for(int k=0; k<8; k++){
          LED(level,j,k,r,g,b);
        }
      for(int j=0; j<8; j++)
        for(int k=0; k<1; k++){
          LED(level,j,k,r,g,b);
        }  
       for(int j=0; j<8; j++)
        for(int k=7; k<8; k++){
          LED(level,j,k,r,g,b);
        } 
}

Next is the function that will clear the leds from the functions above.

void waterFountainFAclean(int level){
      for(int j=0; j<1; j++)
        for(int k=0; k<8; k++){
          LED(level,j,k,0,0,0);
        }
      for(int j=7; j<8; j++)
        for(int k=0; k<8; k++){
          LED(level,j,k,0,0,0);
        }
      for(int j=0; j<8; j++)
        for(int k=0; k<1; k++){
          LED(level,j,k,0,0,0);
        }  
       for(int j=0; j<8; j++)
        for(int k=7; k<8; k++){
          LED(level,j,k,0,0,0);
        } 
}

And next is the main function.

void waterfountain(){
  start=millis();
  while(millis()-start<8000){
  int t=50,r=random(16),g=random(16),b=random(16);
  for(int i=0; i<8; i++){
     for(int j=3; j<5; j++)
       for(int k=3; k<5; k++){
          LED(i,j,k,r,g,b);
       }
       delay(t);
  }
     for(int j=2; j<6; j++)
       for(int k=2; k<6; k++){
          LED(7,j,k,r,g,b);
       }
     waterFountainF(0);
     delay(t);
     for(int j=1; j<7; j++)
       for(int k=1; k<7; k++){
          LED(7,j,k,r,g,b);
       }
     waterFuntainF(1); 
     delay(t);
     for(int j=0; j<8; j++)
       for(int k=0; k<8; k++){
          LED(7,j,k,r,g,b);
       } 
     waterFountainF(2);
     delay(t);    
     waterFountainFA(6,r,g,b);
     waterFountainF(3);
     delay(t);        
     waterFountainFA(5,r,g,b);
     waterFountainF(4);
     delay(t);       
     waterFountainFA(4,r,g,b);
     waterFountainF(5);
     delay(t);    
     waterFountainFA(3,r,g,b);
     waterFountainF(6);
     delay(t);    
     waterFountainFA(2,r,g,b); 
     waterFountainF(7);
     delay(t);    
     for(int j=2; j<6; j++)
       for(int k=2; k<6; k++){
          LED(7,j,k,0,0,0);
       }
     waterFountainFA(1,r,g,b);   
     delay(t); 
     for(int j=1; j<7; j++)
       for(int k=1; k<7; k++){
          LED(7,j,k,0,0,0);
       } 
     waterFountainFA(0,r,g,b);   
     delay(t);
     waterFountainFAclean(7); 
     delay(t);
     waterFountainFAclean(6); 
     delay(t);
     waterFountainFAclean(5); 
     delay(t);
     waterFountainFAclean(4); 
     delay(t);
     waterFountainFAclean(3); 
     delay(t);
     waterFountainFAclean(2); 
     delay(t);
     waterFountainFAclean(1); 
     delay(t);
     waterFountainFAclean(0); 
     delay(t);
  }        
}

I know this is not easy to visualize what is happen without looking at the cube, but I will describe as much I can. The main function starts with the while millis loop and play the animation for eight seconds. Then will pick a color randomly and following the two for loops which will form the center and top of the fountain. Next the function waterFountainF starts clean the led from the bottom. Next the function waterFountainFA starts forms the top and sides of the fountain following by the waterFountainF. Then two more for loops to clean the top following by the waterFountainFAclean function which will clean the sides of the fountain. Notice the variable values on the functions which in this case are the levels of the cube and colors.


by: Almir Puglia | 362