hendriawan

matrix max7219 v5

Feb 6th, 2019
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //http://xantorohara.github.io/led-matrix-editor/#ff00000000000000
  2. //http://robojax.com/learn/arduino/8x8LED/
  3. //We always have to include the library
  4. #include "LedControl.h"
  5.  
  6.  
  7. /*
  8.   Now we need a LedControl to work with.
  9.  ***** These pin numbers will probably not work with your hardware *****
  10.   pin 12 is connected to the DataIn
  11.   pin 11 is connected to the CLK
  12.   pin 10 is connected to LOAD
  13.   We have only a single MAX72XX.
  14. */
  15. LedControl lc = LedControl(12, 11, 10, 1);
  16. byte LEFT[] = { B00011000, B00110000, B01100000, B11011111, B11011111, B01100000, B00110000, B00011000};
  17. byte RIGHT[] = { B00011000, B00001100, B00000110, B11111011, B11111011, B00000110, B00001100, B00011000};
  18. byte UP[] = { B00011000, B00111100, B01100110, B11011011, B10011001, B00011000, B00011000, B00011000};
  19. byte DN[] = { B00011000, B00011000, B00011000, B10011001, B11011011, B01100110, B00111100, B00011000};
  20. byte DIAMOND[] = { B00011000, B00111100, B01111110, B11111111, B11111111, B01111110, B00111100, B00011000};
  21. byte SQUARE0[] = { B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111};
  22. byte SQUARE1[] = { B00100100, B01000010, B10000001, B00000000, B00000000, B10000001, B01000010, B00100100};
  23. byte SQUARE2[] = { B00000000, B00100100, B01100110, B00000000, B00000000, B01100110, B00100100, B00000000};
  24. byte SQUARE3[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  25.  
  26. byte CIRCLE0[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  27. byte CIRCLE1[] = { B00000000, B00000000, B00011000, B00100100, B00100100, B00011000, B00000000, B00000000};
  28. byte CIRCLE2[] = { B00000000, B00111100, B01000010, B01000010, B01000010, B01000010, B00111100, B00000000};
  29. byte CIRCLE3[] = { B01111110, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B01111110};
  30. byte BANK[8][8];
  31.  
  32. byte VAR1[] = { B10000000,
  33.                 B10000000,
  34.                 B10000000,
  35.                 B10000000,
  36.                 B10000000,
  37.                 B10000000,
  38.                 B10000000,
  39.                 B10000000
  40.               };
  41. byte TEST[] = { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11111111};
  42.  
  43. byte TEMP[8] ;
  44.  
  45. /* we always wait a bit between updates of the display */
  46. unsigned long delaytime =50;
  47.  
  48. void setup() {
  49.   /*
  50.     The MAX72XX is in power-saving mode on startup,
  51.     we have to do a wakeup call
  52.   */
  53.   lc.shutdown(0, false);
  54.   /* Set the brightness to a medium values */
  55.   lc.setIntensity(0, 8);
  56.   /* and clear the display */
  57.   lc.clearDisplay(0);
  58.  
  59. }
  60.  
  61.  
  62. void matrix(byte PARAM[]) {
  63.   for (int i = 0; i < 8; i++) {
  64.     lc.setRow(0, i, PARAM[i]);
  65.   }
  66. }
  67.  
  68. void matrixShiftRIGHT(void) {
  69.   //SHift to left
  70.   memcpy(TEMP, RIGHT, 8); // or strcpy( TEMP, RIGHT);
  71.   for (int j = 8; j > 0; j--) {
  72.     for (int i = 0; i < 8; i++) {
  73.       TEMP[i] = TEMP[i] << j;
  74.     }
  75.     matrix(TEMP);
  76.     delay(delaytime);
  77.     memcpy(TEMP, RIGHT, 8);
  78.   }
  79.  
  80.   for (int j = 1; j < 8; j++) {
  81.     for (int i = 0; i < 8; i++) {
  82.       TEMP[i] = TEMP[i] >> j;
  83.     }
  84.     matrix(TEMP);
  85.     delay(delaytime);
  86.     memcpy(TEMP, RIGHT, 8);
  87.   }
  88. }
  89.  
  90. void matrixShiftLEFT(void) {
  91.  
  92.   //SHift to left
  93.   memcpy(TEMP, LEFT, 8);
  94.   for (int j = 8; j > 0; j--) {
  95.     for (int i = 0; i < 8; i++) {
  96.       TEMP[i] = TEMP[i] >> j;
  97.     }
  98.     matrix(TEMP);
  99.     delay(delaytime);
  100.     memcpy(TEMP, LEFT, 8);
  101.   }
  102.  
  103.   for (int j = 0; j < 8; j++) {
  104.     for (int i = 0; i < 8; i++) {
  105.       TEMP[i] = TEMP[i] << j;
  106.     }
  107.     matrix(TEMP);
  108.     delay(delaytime);
  109.     memcpy(TEMP, LEFT, 8);
  110.   }
  111. }
  112.  
  113. void matrixShiftUP(void) {
  114.   int k = 0;
  115.   memcpy(TEMP, UP, 8);
  116.   memcpy(BANK[k++], TEMP, 8);
  117.   //  matrix(TEMP);
  118.   //  delay(delaytime);
  119.   for (int j = 0; j < 8; j++) {
  120.     for (int i = 7; i > 0; i--) {
  121.       TEMP[i] = TEMP[i - 1];
  122.     }
  123.     TEMP[0] = 0;
  124.     //    matrix(TEMP);
  125.     memcpy(BANK[k++], TEMP, 8);
  126.     //    delay(delaytime);
  127.   }
  128.  
  129.   for (int j = 7; j >= 0; j--) {
  130.     matrix(BANK[j]);
  131.     delay(delaytime);
  132.   }
  133.  
  134.  
  135.   memcpy(TEMP, UP, 8);
  136.   for (int i = 0; i < 7; i++) {
  137.     for (int i = 0; i < 7; i++) {
  138.       TEMP[i] = TEMP[i + 1];
  139.     }
  140.     TEMP[7] = 0;
  141.     matrix(TEMP);
  142.     delay(delaytime);
  143.   }
  144. }
  145.  
  146. void matrixShiftDN(void) {
  147.   memcpy(TEMP, DN, 8);
  148.   matrix(TEMP);
  149.   delay(delaytime);
  150.   for (int i = 0; i <= 8; i++) {
  151.     for (int i = 6; i >= 0; i--) {
  152.       TEMP[i + 1] = TEMP[i];
  153.     }
  154.     TEMP[0] = 0;
  155.     matrix(TEMP);
  156.     delay(delaytime);
  157.   }
  158. }
  159.  
  160. void loop() {
  161.   matrixShiftLEFT();
  162.   matrixShiftRIGHT();
  163.   matrixShiftUP();
  164.   //  matrix(LEFT);
  165.   //  delay(delaytime);
  166.   //  matrix(RIGHT);
  167.   //  delay(delaytime);
  168.   //  matrix(UP);
  169.   //  delay(delaytime);
  170.   //  matrix(DIAMOND);
  171.   //  delay(delaytime);
  172.   //  matrix(SQUARE);
  173.   //  delay(delaytime);
  174.   //  matrix(SQUARE1);
  175.   //  delay(delaytime);
  176.   //  matrix(SQUARE2);
  177.   //  delay(delaytime);
  178.   //  matrix(SQUARE3);
  179.   //  delay(delaytime);
  180.  
  181.   //    matrix(CIRCLE0);
  182.   //    delay(delaytime);
  183.   //    matrix(CIRCLE1);
  184.   //    delay(delaytime);
  185.   //    matrix(CIRCLE2);
  186.   //    delay(delaytime);
  187.   //    matrix(CIRCLE3);
  188.   //    delay(delaytime);
  189.  
  190.   //  for (int i = 0; i < 4; i++) {
  191.   //    matrix(CIRCLE3);
  192.   //    delay(delaytime);
  193.   //    matrix(CIRCLE2);
  194.   //    delay(delaytime);
  195.   //    matrix(CIRCLE1);
  196.   //    delay(delaytime);
  197.   //  }
  198.   //  lc.clearDisplay(0);
  199.   //  delay(100);
  200. }
Advertisement
Add Comment
Please, Sign In to add comment