hendriawan

matrix max7219 v4

Feb 6th, 2019
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //http://robojax.com/learn/arduino/8x8LED/
  2. //http://xantorohara.github.io/led-matrix-editor/#3810101010101810
  3.  
  4. //We always have to include the library
  5. #include "LedControl.h"
  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 DIAMOND[] = { B00011000, B00111100, B01111110, B11111111, B11111111, B01111110, B00111100, B00011000};
  20. byte SQUARE0[] = { B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111};
  21. byte SQUARE1[] = { B00100100, B01000010, B10000001, B00000000, B00000000, B10000001, B01000010, B00100100};
  22. byte SQUARE2[] = { B00000000, B00100100, B01100110, B00000000, B00000000, B01100110, B00100100, B00000000};
  23. byte SQUARE3[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  24.  
  25. byte CIRCLE0[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  26. byte CIRCLE1[] = { B00000000, B00000000, B00011000, B00100100, B00100100, B00011000, B00000000, B00000000};
  27. byte CIRCLE2[] = { B00000000, B00111100, B01000010, B01000010, B01000010, B01000010, B00111100, B00000000};
  28. byte CIRCLE3[] = { B01111110, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B01111110};
  29.  
  30. byte VAR1[] = { B10000000, B10000000, B10000000, B10000000, B10000000, B10000000, B10000000, B10000000};
  31. byte TEMP[8] ;
  32.  
  33. /* we always wait a bit between updates of the display */
  34. unsigned long delaytime = 1000;
  35.  
  36. void setup() {
  37.   /*
  38.     The MAX72XX is in power-saving mode on startup,
  39.     we have to do a wakeup call
  40.   */
  41.   lc.shutdown(0, false);
  42.   /* Set the brightness to a medium values */
  43.   lc.setIntensity(0, 8);
  44.   /* and clear the display */
  45.   lc.clearDisplay(0);
  46.  
  47. }
  48.  
  49.  
  50. void matrix(byte PARAM[]) {
  51.   for (int i = 0; i < 8; i++) {
  52.     lc.setRow(0, i, PARAM[i]);
  53.   }
  54. }
  55.  
  56. void matrixShiftRIGHT(void) {
  57.   //SHift to left
  58.   memcpy(TEMP, RIGHT, 8); // or strcpy( TEMP, RIGHT);
  59.   for (int j = 8; j >= 0; j--) {
  60.     for (int i = 0; i < 8; i++) {
  61.       TEMP[i] = TEMP[i] << j;
  62.     }
  63.     matrix(TEMP);
  64.     delay(delaytime);
  65.     memcpy(TEMP, RIGHT, 8);
  66.   }
  67.  
  68.   for (int j = 1; j < 8; j++) {
  69.     for (int i = 0; i < 8; i++) {
  70.       TEMP[i] = TEMP[i] >> j;
  71.     }
  72.     matrix(TEMP);
  73.     delay(delaytime);
  74.     memcpy(TEMP, RIGHT, 8);
  75.   }
  76. }
  77.  
  78. void matrixShiftLEFT(void) {
  79.   //SHift to left
  80.   for (int j = 0; 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, LEFT, 8);
  87.   }
  88.  
  89. //  memcpy(TEMP, LEFT, 8);
  90. //  for (int j = 1; j < 8; j++) {
  91. //    for (int i = 0; i < 8; i++) {
  92. //      TEMP[i] = TEMP[i] >> j;
  93. //    }
  94. //    matrix(TEMP);
  95. //    delay(delaytime);
  96. //    memcpy(TEMP, LEFT, 8);
  97. //  }
  98.  
  99. }
  100.  
  101. void loop() {
  102.   matrixShiftLEFT();
  103.  
  104.  
  105.  
  106.   //  matrix(LEFT);
  107.   //  delay(delaytime);
  108.   //  matrix(RIGHT);
  109.   //  delay(delaytime);
  110.   //  matrix(UP);
  111.   //  delay(delaytime);
  112.   //  matrix(DIAMOND);
  113.   //  delay(delaytime);
  114.   //  matrix(SQUARE);
  115.   //  delay(delaytime);
  116.   //  matrix(SQUARE1);
  117.   //  delay(delaytime);
  118.   //  matrix(SQUARE2);
  119.   //  delay(delaytime);
  120.   //  matrix(SQUARE3);
  121.   //  delay(delaytime);
  122.  
  123.   //    matrix(CIRCLE0);
  124.   //    delay(delaytime);
  125.   //    matrix(CIRCLE1);
  126.   //    delay(delaytime);
  127.   //    matrix(CIRCLE2);
  128.   //    delay(delaytime);
  129.   //    matrix(CIRCLE3);
  130.   //    delay(delaytime);
  131.  
  132.   //  for (int i = 0; i < 4; i++) {
  133.   //    matrix(CIRCLE3);
  134.   //    delay(delaytime);
  135.   //    matrix(CIRCLE2);
  136.   //    delay(delaytime);
  137.   //    matrix(CIRCLE1);
  138.   //    delay(delaytime);
  139.   //  }
  140.   //  lc.clearDisplay(0);
  141.   //  delay(100);
  142. }
Advertisement
Add Comment
Please, Sign In to add comment