Advertisement
WayGroovy

Untitled

Dec 1st, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. //We always have to include the library
  2. #include "LedControl.h"
  3.  
  4. /*
  5.  Now we need a LedControl to work with.
  6.  PD0 is connected to the DataIn
  7.  PD1 is connected to the CS
  8.  PD2 is connected to CLK
  9.  ***** Please set the number of devices you have *****
  10.  But the maximum default of 8 MAX72XX wil also work.
  11.  */
  12. LedControl lc=LedControl(23,25,24,4);
  13.  
  14. /* we always wait a bit between updates of the display */
  15. unsigned long delaytime=125;
  16.  
  17. /*
  18.  This time we have more than one device.
  19.  But all of them have to be initialized
  20.  individually.
  21.  */
  22. void setup() {
  23.   //we have already set the number of devices when we created the LedControl
  24.   int devices=lc.getDeviceCount();
  25.   //we have to init all devices in a loop
  26.   for(int address=0;address<devices;address++) {
  27.     /*The MAX72XX is in power-saving mode on startup*/
  28.     lc.shutdown(address,false);
  29.     /* Set the brightness to a medium values */
  30.     lc.setIntensity(address,8);
  31.     /* and clear the display */
  32.     lc.clearDisplay(address);
  33.   }
  34. }
  35.  
  36. void loop() {
  37.   //read the number cascaded devices
  38.   int devices=lc.getDeviceCount();
  39.   int rowOn=4, rowOff=0;
  40.  
  41.   //we have to init all devices in a loop
  42. //  for(int col=0;col<8;col++) {
  43.   int col=7;
  44.   int address=0;
  45.  
  46.   lc.setLed(address,0,col,true);
  47.   lc.setLed(address,1,col,true);
  48.   lc.setLed(address,2,col,true);
  49.  
  50.  
  51.     for(int rowCount=0;rowCount<10;rowCount+=1) {
  52. //      for(int address=0;address<devices;address++) {
  53.  
  54. //        delay(delaytime);
  55.         if (rowCount<5){
  56.           rowOn=rowCount+3;
  57.           rowOff=rowCount;
  58.         } else {
  59.           rowOn=9-rowCount;
  60.           rowOff=12-rowCount;
  61.         }
  62.        
  63.         lc.setLed(address,rowOn,col,true);
  64.         lc.setLed(address,rowOff,col,false);
  65.         delay(delaytime);
  66.  
  67.         if(rowCount==9){
  68.           rowCount=-1;
  69.           col=col-1;
  70.           if(col==-1){
  71.             delaytime=delaytime/2;
  72.             col=7;
  73.             address=address+1;
  74.             if(address==4){
  75.               for(int rowClear=0;rowClear<8;rowClear++) {
  76.                 for(int addressClear=4;addressClear>-1;addressClear--) {
  77.                     for(int colClear=0;colClear<8;colClear++) {
  78.                       lc.setLed(addressClear,rowClear,colClear,false);
  79. //                      delay(delaytime);
  80.                     }
  81.                   }
  82.                 }
  83.             delaytime=125;
  84.             break;
  85.             }
  86.           }
  87.           lc.setLed(address,0,col,true);
  88.           lc.setLed(address,1,col,true);
  89.           lc.setLed(address,2,col,true);
  90.         }
  91.    }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement