Advertisement
Guest User

Arduino LED Cube

a guest
Oct 2nd, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.98 KB | None | 0 0
  1. #include <LedCube.h>
  2.  
  3. byte levelPins[] = {22,23,24};
  4. byte colPins[] = {31,32,33,34,35,36,37,38,39};
  5.  
  6. LedCube cube(3, levelPins, colPins);
  7.  
  8. void setup ()
  9. {
  10. }
  11.  
  12. void loop ()
  13. {
  14.     delay(100);
  15.     cube.enableBuffer(false);
  16.    
  17.     // light one level at a time, increasing speed each time
  18.     for(byte t=25; t>2; t-=2)
  19.     {
  20.         for(byte l=0; l<cube.getNumLevels(); l++){
  21.             cube.lightLevel(l,t);
  22.         }
  23.         cube.lightLevel(1, t);
  24.     }
  25.    
  26.     // single random light at a time
  27.     cube.randomLight(random(25,100),100);
  28.    
  29.     // random column drop
  30.     for(byte x=0; x<=15; x++) {
  31.         cube.lightDrop(random(0,cube.getNumCols()), random(50,200));
  32.     }
  33.    
  34.     // circle around cube at a random level
  35.     for(byte x=0; x<=5; x++) {
  36.         cube.lightPerimeter(random(0,cube.getNumLevels()), random(1,5), random(25,100));
  37.     }
  38.    
  39.     // random columns
  40.     cube.randomColumn(25);
  41.    
  42.     // turn off a single column randomly
  43.     cube.enableBuffer();
  44.     for(byte c=0; c<20; c++)
  45.     {
  46.         cube.fillBuffer();
  47.         cube.invertBuffer();
  48.         cube.randomColumn();
  49.         cube.drawBuffer(12);
  50.     }
  51.     cube.enableBuffer(false);
  52.     cube.invertBuffer(false);
  53.    
  54.     // cols in and out
  55.     for(byte c=1, d=0; c<=36; c++)
  56.     {
  57.         if(c%2 == 0){
  58.             for(d=0; d<20; d++) {
  59.                 cube.lightColumn(2,1);
  60.                 cube.lightColumn(4,1);
  61.                 cube.lightColumn(6,1);
  62.                 cube.lightColumn(8,1);
  63.             }
  64.         } else if(c%4 == 1) {
  65.             for(d=0; d<30; d++) {
  66.                 cube.lightColumn(1,1);
  67.                 cube.lightColumn(3,1);
  68.                 cube.lightColumn(7,1);
  69.                 cube.lightColumn(9,1);
  70.             }
  71.         } else {
  72.             for(d=0; d<70; d++) {
  73.                 cube.lightColumn(5,1);
  74.             }
  75.         }
  76.     }
  77.    
  78.     // diamond and box
  79.     byte diamond[] = {0,4, 1,1, 1,3, 1,4, 1,5, 1,7, 2,4};
  80.     byte box[] = {0,0, 0,1, 0,2, 0,3, 0,5, 0,6, 0,7, 0,8,  1,0, 1,2, 1,6, 1,8,  2,0, 2,1, 2,2, 2,3, 2,5, 2,6, 2,7, 2,8};
  81.     cube.lightSequence(box, sizeof(box), 200);
  82.     cube.lightSequence(diamond, sizeof(diamond), 400);
  83.    
  84.         // remaining effects use the buffer
  85.     cube.enableBuffer();
  86.  
  87.         // pyramids
  88.     cube.fillBuffer();
  89.         cube.invertBuffer();
  90.         cube.lightPerimeter(0);
  91.     byte corners[] = {1,0, 1,2, 1,6, 1,8};
  92.         cube.lightSequence(corners, sizeof(corners));
  93.     cube.drawBuffer(100);
  94.         cube.lightPerimeter(2);
  95.         cube.invertBuffer(false);
  96.         cube.lightPerimeter(0);
  97.     cube.drawBuffer(100);
  98.        
  99.     // helicopter effect
  100.     byte topSeq[8] = {0,3,6,7,8,5,2,1};
  101.     byte midSeq[8] = {5,8,7,6,3,0,1,2};
  102.     byte botSeq[8] = {8,5,2,1,0,3,6,7};
  103.     for(byte q = 0; q<3; q++){
  104.             for(byte r = 0; r<7; r++){
  105.                 for(byte s= 0; s<8; s++){
  106.                     cube.clearBuffer();
  107.                     cube.lightOn(0,botSeq[s]);
  108.                     cube.lightOn(1,midSeq[s]);
  109.                     cube.lightOn(2,topSeq[s]);
  110.                     cube.drawBuffer(100/(r+1));
  111.                 }
  112.             }
  113.         }
  114.    
  115.     // turn off one light at a time
  116.     cube.fillBuffer();
  117.     cube.drawBuffer(25);
  118.     for(byte w=0, l, c; w<27; ){
  119.         l = random(0,cube.getNumLevels());
  120.         c = random(0,cube.getNumCols());
  121.         if(cube.getBufferAt(l,c)){
  122.             cube.lightOff(l,c);
  123.             cube.drawBuffer(15+w*2);
  124.             w++;
  125.         }
  126.     }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement