SophiYo

ssss

May 1st, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 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.  ***** These pin numbers will probably not work with your hardware *****
  7.  pin 12 is connected to the DataIn
  8.  pin 11 is connected to the CLK
  9.  pin 10 is connected to LOAD
  10.  We have only a single MAX72XX.
  11.  */
  12. LedControl lc=LedControl(12,11,10,1);
  13.  
  14. /* we always wait a bit between updates of the display */
  15. unsigned long delaytime=1000;
  16.  
  17. void setup() {
  18.   /*
  19.    The MAX72XX is in power-saving mode on startup,
  20.    we have to do a wakeup call
  21.    */
  22.   lc.shutdown(0,false);
  23.   /* Set the brightness to a medium values */
  24.   lc.setIntensity(0,8);
  25.   /* and clear the display */
  26.   lc.clearDisplay(0);
  27. }
  28.  
  29. /*
  30.  This method will display the characters for the
  31.  word "Arduino" one after the other on the matrix.
  32.  (you need at least 5x7 leds to see the whole chars)
  33.  */
  34. void writeArduinoOnMatrix() {
  35.   /* here is the data for the characters */
  36.   byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
  37.   byte r[5]={B00111110,B00010000,B00100000,B00100000,B00010000};
  38.   byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
  39.   byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
  40.   byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};
  41.   byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
  42.   byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};
  43.  
  44.   /* now display them one by one with a small delay */
  45.   lc.setRow(0,0,a[0]);
  46.   lc.setRow(0,1,a[1]);
  47.   lc.setRow(0,2,a[2]);
  48.   lc.setRow(0,3,a[3]);
  49.   lc.setRow(0,4,a[4]);
  50.   delay(delaytime);
  51.   lc.setRow(0,0,r[0]);
  52.   lc.setRow(0,1,r[1]);
  53.   lc.setRow(0,2,r[2]);
  54.   lc.setRow(0,3,r[3]);
  55.   lc.setRow(0,4,r[4]);
  56.   delay(delaytime);
  57.   lc.setRow(0,0,d[0]);
  58.   lc.setRow(0,1,d[1]);
  59.   lc.setRow(0,2,d[2]);
  60.   lc.setRow(0,3,d[3]);
  61.   lc.setRow(0,4,d[4]);
  62.   delay(delaytime);
  63.   lc.setRow(0,0,u[0]);
  64.   lc.setRow(0,1,u[1]);
  65.   lc.setRow(0,2,u[2]);
  66.   lc.setRow(0,3,u[3]);
  67.   lc.setRow(0,4,u[4]);
  68.   delay(delaytime);
  69.   lc.setRow(0,0,i[0]);
  70.   lc.setRow(0,1,i[1]);
  71.   lc.setRow(0,2,i[2]);
  72.   lc.setRow(0,3,i[3]);
  73.   lc.setRow(0,4,i[4]);
  74.   delay(delaytime);
  75.   lc.setRow(0,0,n[0]);
  76.   lc.setRow(0,1,n[1]);
  77.   lc.setRow(0,2,n[2]);
  78.   lc.setRow(0,3,n[3]);
  79.   lc.setRow(0,4,n[4]);
  80.   delay(delaytime);
  81.   lc.setRow(0,0,o[0]);
  82.   lc.setRow(0,1,o[1]);
  83.   lc.setRow(0,2,o[2]);
  84.   lc.setRow(0,3,o[3]);
  85.   lc.setRow(0,4,o[4]);
  86.   delay(delaytime);
  87.   lc.setRow(0,0,0);
  88.   lc.setRow(0,1,0);
  89.   lc.setRow(0,2,0);
  90.   lc.setRow(0,3,0);
  91.   lc.setRow(0,4,0);
  92.   delay(delaytime);
  93. }
  94.  
  95. /*
  96.   This function lights up a some Leds in a row.
  97.  The pattern will be repeated on every row.
  98.  The pattern will blink along with the row-number.
  99.  row number 4 (index==3) will blink 4 times etc.
  100.  */
  101. void rows() {
  102.   for(int row=0;row<8;row++) {
  103.     delay(delaytime);
  104.     lc.setRow(0,row,B10100000);
  105.     delay(delaytime);
  106.     lc.setRow(0,row,(byte)0);
  107.     for(int i=0;i<row;i++) {
  108.       delay(delaytime);
  109.       lc.setRow(0,row,B10100000);
  110.       delay(delaytime);
  111.       lc.setRow(0,row,(byte)0);
  112.     }
  113.   }
  114. }
  115.  
  116. /*
  117.   This function lights up a some Leds in a column.
  118.  The pattern will be repeated on every column.
  119.  The pattern will blink along with the column-number.
  120.  column number 4 (index==3) will blink 4 times etc.
  121.  */
  122. void columns() {
  123.   for(int col=0;col<8;col++) {
  124.     delay(delaytime);
  125.     lc.setColumn(0,col,B10100000);
  126.     delay(delaytime);
  127.     lc.setColumn(0,col,(byte)0);
  128.     for(int i=0;i<col;i++) {
  129.       delay(delaytime);
  130.       lc.setColumn(0,col,B10100000);
  131.       delay(delaytime);
  132.       lc.setColumn(0,col,(byte)0);
  133.     }
  134.   }
  135. }
  136.  
  137. /*
  138.  This function will light up every Led on the matrix.
  139.  The led will blink along with the row-number.
  140.  row number 4 (index==3) will blink 4 times etc.
  141.  */
  142. void single() {
  143.   for(int row=0;row<8;row++) {
  144.     for(int col=0;col<8;col++) {
  145.       delay(delaytime);
  146.       lc.setLed(0,row,col,true);
  147.       delay(delaytime);
  148.       for(int i=0;i<col;i++) {
  149.         lc.setLed(0,row,col,false);
  150.         delay(delaytime);
  151.         lc.setLed(0,row,col,true);
  152.         delay(delaytime);
  153.       }
  154.     }
  155.   }
  156. }
  157.  
  158. void loop() {
  159.   writeArduinoOnMatrix();
  160.   rows();
  161.   columns();
  162.   single();
  163. }
Advertisement
Add Comment
Please, Sign In to add comment