hendriawan

matrix max7219 v6-no interrupt

Feb 8th, 2019
680
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. int inPinLEFT = 2;
  17. int inPinRIGHT = 3;
  18. int inPinOFF = 18;
  19. volatile byte state = 0;
  20. int val = 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.   pinMode(inPinLEFT, INPUT);
  66.   pinMode(inPinRIGHT, INPUT);
  67.   pinMode(inPinOFF, INPUT);
  68.  
  69. }
  70.  
  71.  
  72. void matrix(byte PARAM[]) {
  73.   for (int i = 0; i < 8; i++) {
  74.     lc.setRow(0, i, PARAM[i]);
  75.   }
  76. }
  77.  
  78. void matrixShiftRIGHT(void) {
  79.   //SHift to left
  80.   memcpy(TEMP, RIGHT, 8); // or strcpy( TEMP, RIGHT);
  81.   for (int j = 8; j > 0; j--) {
  82.     for (int i = 0; i < 8; i++) {
  83.       TEMP[i] = TEMP[i] << j;
  84.     }
  85.     matrix(TEMP);
  86.     delay(delaytime);
  87.     memcpy(TEMP, RIGHT, 8);
  88.   }
  89.  
  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, RIGHT, 8);
  97.   }
  98. }
  99.  
  100. void matrixShiftLEFT(void) {
  101.  
  102.   //SHift to left
  103.   memcpy(TEMP, LEFT, 8);
  104.   for (int j = 8; j > 0; j--) {
  105.     for (int i = 0; i < 8; i++) {
  106.       TEMP[i] = TEMP[i] >> j;
  107.     }
  108.     matrix(TEMP);
  109.     delay(delaytime);
  110.     memcpy(TEMP, LEFT, 8);
  111.   }
  112.  
  113.   for (int j = 0; j < 8; j++) {
  114.     for (int i = 0; i < 8; i++) {
  115.       TEMP[i] = TEMP[i] << j;
  116.     }
  117.     matrix(TEMP);
  118.     delay(delaytime);
  119.     memcpy(TEMP, LEFT, 8);
  120.   }
  121. }
  122.  
  123. void matrixShiftUP(void) {
  124.   int k = 0;
  125.   memcpy(TEMP, UP, 8);
  126.   memcpy(BANK[k++], TEMP, 8);
  127.   //  matrix(TEMP);
  128.   //  delay(delaytime);
  129.   for (int j = 0; j < 8; j++) {
  130.     for (int i = 7; i > 0; i--) {
  131.       TEMP[i] = TEMP[i - 1];
  132.     }
  133.     TEMP[0] = 0;
  134.     //    matrix(TEMP);
  135.     memcpy(BANK[k++], TEMP, 8);
  136.     //    delay(delaytime);
  137.   }
  138.  
  139.   for (int j = 7; j >= 0; j--) {
  140.     matrix(BANK[j]);
  141.     delay(delaytime);
  142.   }
  143.  
  144.  
  145.   memcpy(TEMP, UP, 8);
  146.   for (int i = 0; i < 7; i++) {
  147.     for (int i = 0; i < 7; i++) {
  148.       TEMP[i] = TEMP[i + 1];
  149.     }
  150.     TEMP[7] = 0;
  151.     matrix(TEMP);
  152.     delay(delaytime);
  153.   }
  154. }
  155.  
  156. void matrixShiftDN(void) {
  157.   memcpy(TEMP, DN, 8);
  158.   matrix(TEMP);
  159.   delay(delaytime);
  160.   for (int i = 0; i <= 8; i++) {
  161.     for (int i = 6; i >= 0; i--) {
  162.       TEMP[i + 1] = TEMP[i];
  163.     }
  164.     TEMP[0] = 0;
  165.     matrix(TEMP);
  166.     delay(delaytime);
  167.   }
  168. }
  169.  
  170. void loop() {
  171.   if (digitalRead(2) == LOW)
  172.     matrixShiftRIGHT();
  173.   if (digitalRead(3) == LOW)
  174.     matrixShiftLEFT();
  175.   if (digitalRead(18) == LOW)
  176.     lc.clearDisplay(0);
  177.  
  178.  
  179.   //  matrix(LEFT);
  180.   //  delay(delaytime);
  181.   //  matrix(RIGHT);
  182.   //  delay(delaytime);
  183.   //  matrix(UP);
  184.   //  delay(delaytime);
  185.   //  matrix(DIAMOND);
  186.   //  delay(delaytime);
  187.   //  matrix(SQUARE);
  188.   //  delay(delaytime);
  189.   //  matrix(SQUARE1);
  190.   //  delay(delaytime);
  191.   //  matrix(SQUARE2);
  192.   //  delay(delaytime);
  193.   //  matrix(SQUARE3);
  194.   //  delay(delaytime);
  195.  
  196.   //    matrix(CIRCLE0);
  197.   //    delay(delaytime);
  198.   //    matrix(CIRCLE1);
  199.   //    delay(delaytime);
  200.   //    matrix(CIRCLE2);
  201.   //    delay(delaytime);
  202.   //    matrix(CIRCLE3);
  203.   //    delay(delaytime);
  204.  
  205.   //  for (int i = 0; i < 4; i++) {
  206.   //    matrix(CIRCLE3);
  207.   //    delay(delaytime);
  208.   //    matrix(CIRCLE2);
  209.   //    delay(delaytime);
  210.   //    matrix(CIRCLE1);
  211.   //    delay(delaytime);
  212.   //  }
  213.   //  lc.clearDisplay(0);
  214.   //  delay(100);
  215. }
Advertisement
Add Comment
Please, Sign In to add comment