hendriawan

matrix max7219 v7

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