hendriawan

matrix max7219 v6

Feb 6th, 2019
807
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.  
  16. const byte interruptPin = 2;
  17. volatile byte state = 0;
  18.  
  19. LedControl lc = LedControl(12, 11, 10, 1);
  20. byte LEFT[] = { B00011000, B00110000, B01100000, B11011111, B11011111, B01100000, B00110000, B00011000};
  21. byte RIGHT[] = { B00011000, B00001100, B00000110, B11111011, B11111011, B00000110, B00001100, B00011000};
  22. byte UP[] = { B00011000, B00111100, B01100110, B11011011, B10011001, B00011000, B00011000, B00011000};
  23. byte DN[] = { B00011000, B00011000, B00011000, B10011001, B11011011, B01100110, B00111100, B00011000};
  24. byte DIAMOND[] = { B00011000, B00111100, B01111110, B11111111, B11111111, B01111110, B00111100, B00011000};
  25. byte SQUARE0[] = { B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111};
  26. byte SQUARE1[] = { B00100100, B01000010, B10000001, B00000000, B00000000, B10000001, B01000010, B00100100};
  27. byte SQUARE2[] = { B00000000, B00100100, B01100110, B00000000, B00000000, B01100110, B00100100, B00000000};
  28. byte SQUARE3[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  29.  
  30. byte CIRCLE0[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  31. byte CIRCLE1[] = { B00000000, B00000000, B00011000, B00100100, B00100100, B00011000, B00000000, B00000000};
  32. byte CIRCLE2[] = { B00000000, B00111100, B01000010, B01000010, B01000010, B01000010, B00111100, B00000000};
  33. byte CIRCLE3[] = { B01111110, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B01111110};
  34. byte BANK[8][8];
  35.  
  36. byte VAR1[] = { B10000000,
  37.                 B10000000,
  38.                 B10000000,
  39.                 B10000000,
  40.                 B10000000,
  41.                 B10000000,
  42.                 B10000000,
  43.                 B10000000
  44.               };
  45. byte TEST[] = { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11111111};
  46.  
  47. byte TEMP[8] ;
  48.  
  49. /* we always wait a bit between updates of the display */
  50. unsigned long delaytime = 50;
  51.  
  52. void setup() {
  53.   /*
  54.     The MAX72XX is in power-saving mode on startup,
  55.     we have to do a wakeup call
  56.   */
  57.   lc.shutdown(0, false);
  58.   /* Set the brightness to a medium values */
  59.   lc.setIntensity(0, 8);
  60.   /* and clear the display */
  61.   lc.clearDisplay(0);
  62.  
  63.   attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
  64.  
  65. }
  66.  
  67.  
  68. void matrix(byte PARAM[]) {
  69.   for (int i = 0; i < 8; i++) {
  70.     lc.setRow(0, i, PARAM[i]);
  71.   }
  72. }
  73.  
  74. void matrixShiftRIGHT(void) {
  75.   //SHift to left
  76.   memcpy(TEMP, RIGHT, 8); // or strcpy( TEMP, RIGHT);
  77.   for (int j = 8; j > 0; j--) {
  78.     for (int i = 0; i < 8; i++) {
  79.       TEMP[i] = TEMP[i] << j;
  80.     }
  81.     matrix(TEMP);
  82.     delay(delaytime);
  83.     memcpy(TEMP, RIGHT, 8);
  84.   }
  85.  
  86.   for (int j = 1; j < 8; j++) {
  87.     for (int i = 0; i < 8; i++) {
  88.       TEMP[i] = TEMP[i] >> j;
  89.     }
  90.     matrix(TEMP);
  91.     delay(delaytime);
  92.     memcpy(TEMP, RIGHT, 8);
  93.   }
  94. }
  95.  
  96. void matrixShiftLEFT(void) {
  97.  
  98.   //SHift to left
  99.   memcpy(TEMP, LEFT, 8);
  100.   for (int j = 8; j > 0; j--) {
  101.     for (int i = 0; i < 8; i++) {
  102.       TEMP[i] = TEMP[i] >> j;
  103.     }
  104.     matrix(TEMP);
  105.     delay(delaytime);
  106.     memcpy(TEMP, LEFT, 8);
  107.   }
  108.  
  109.   for (int j = 0; j < 8; j++) {
  110.     for (int i = 0; i < 8; i++) {
  111.       TEMP[i] = TEMP[i] << j;
  112.     }
  113.     matrix(TEMP);
  114.     delay(delaytime);
  115.     memcpy(TEMP, LEFT, 8);
  116.   }
  117. }
  118.  
  119. void matrixShiftUP(void) {
  120.   int k = 0;
  121.   memcpy(TEMP, UP, 8);
  122.   memcpy(BANK[k++], TEMP, 8);
  123.   //  matrix(TEMP);
  124.   //  delay(delaytime);
  125.   for (int j = 0; j < 8; j++) {
  126.     for (int i = 7; i > 0; i--) {
  127.       TEMP[i] = TEMP[i - 1];
  128.     }
  129.     TEMP[0] = 0;
  130.     //    matrix(TEMP);
  131.     memcpy(BANK[k++], TEMP, 8);
  132.     //    delay(delaytime);
  133.   }
  134.  
  135.   for (int j = 7; j >= 0; j--) {
  136.     matrix(BANK[j]);
  137.     delay(delaytime);
  138.   }
  139.  
  140.  
  141.   memcpy(TEMP, UP, 8);
  142.   for (int i = 0; i < 7; i++) {
  143.     for (int i = 0; i < 7; i++) {
  144.       TEMP[i] = TEMP[i + 1];
  145.     }
  146.     TEMP[7] = 0;
  147.     matrix(TEMP);
  148.     delay(delaytime);
  149.   }
  150. }
  151.  
  152. void matrixShiftDN(void) {
  153.   memcpy(TEMP, DN, 8);
  154.   matrix(TEMP);
  155.   delay(delaytime);
  156.   for (int i = 0; i <= 8; i++) {
  157.     for (int i = 6; i >= 0; i--) {
  158.       TEMP[i + 1] = TEMP[i];
  159.     }
  160.     TEMP[0] = 0;
  161.     matrix(TEMP);
  162.     delay(delaytime);
  163.   }
  164. }
  165.  
  166. void loop() {
  167. //  switch (state) {
  168. //    case 0:
  169. //      break;
  170. //    case 1:
  171. //      break;
  172. //  }
  173.   if (state == 0) {
  174.     matrixShiftRIGHT();
  175.   } if(state==1){
  176.     matrixShiftLEFT();
  177.   }
  178. //  matrixShiftUP();
  179. //  matrixShiftUP();
  180. //  matrixShiftUP();
  181. //  matrixShiftLEFT();
  182. //  matrixShiftLEFT();
  183. //  matrixShiftLEFT();
  184. //  matrixShiftRIGHT();
  185. //  matrixShiftRIGHT();
  186. //  matrixShiftRIGHT();
  187.  
  188.   //  matrix(LEFT);
  189.   //  delay(delaytime);
  190.   //  matrix(RIGHT);
  191.   //  delay(delaytime);
  192.   //  matrix(UP);
  193.   //  delay(delaytime);
  194.   //  matrix(DIAMOND);
  195.   //  delay(delaytime);
  196.   //  matrix(SQUARE);
  197.   //  delay(delaytime);
  198.   //  matrix(SQUARE1);
  199.   //  delay(delaytime);
  200.   //  matrix(SQUARE2);
  201.   //  delay(delaytime);
  202.   //  matrix(SQUARE3);
  203.   //  delay(delaytime);
  204.  
  205.   //    matrix(CIRCLE0);
  206.   //    delay(delaytime);
  207.   //    matrix(CIRCLE1);
  208.   //    delay(delaytime);
  209.   //    matrix(CIRCLE2);
  210.   //    delay(delaytime);
  211.   //    matrix(CIRCLE3);
  212.   //    delay(delaytime);
  213.  
  214.   //  for (int i = 0; i < 4; i++) {
  215.   //    matrix(CIRCLE3);
  216.   //    delay(delaytime);
  217.   //    matrix(CIRCLE2);
  218.   //    delay(delaytime);
  219.   //    matrix(CIRCLE1);
  220.   //    delay(delaytime);
  221.   //  }
  222.   //  lc.clearDisplay(0);
  223.   //  delay(100);
  224. }
  225.  
  226. void blink() {
  227.   state = 1;
  228. }
Advertisement
Add Comment
Please, Sign In to add comment