hendriawan

matrix max7219 v3

Feb 5th, 2019
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //We always have to include the library
  2. #include "LedControl.h"
  3.  
  4. /*
  5.   Now we need a LedControl to work with.
  6.  ***** These pin numbers will probably not work with your hardware *****
  7.   pin 12 is connected to the DataIn
  8.   pin 11 is connected to the CLK
  9.   pin 10 is connected to LOAD
  10.   We have only a single MAX72XX.
  11. */
  12. LedControl lc = LedControl(12, 11, 10, 1);
  13. byte LEFT[] = { B00011000, B00110000, B01100000, B11011111, B11011111, B01100000, B00110000, B00011000};
  14. byte RIGHT[] = { B00011000, B00001100, B00000110, B11111011, B11111011, B00000110, B00001100, B00011000};
  15. byte UP[] = { B00011000, B00111100, B01100110, B11011011, B10011001, B00011000, B00011000, B00011000};
  16. byte DIAMOND[] = { B00011000, B00111100, B01111110, B11111111, B11111111, B01111110, B00111100, B00011000};
  17. byte SQUARE0[] = { B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111};
  18. byte SQUARE1[] = { B00100100, B01000010, B10000001, B00000000, B00000000, B10000001, B01000010, B00100100};
  19. byte SQUARE2[] = { B00000000, B00100100, B01100110, B00000000, B00000000, B01100110, B00100100, B00000000};
  20. byte SQUARE3[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  21.  
  22. byte CIRCLE0[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
  23. byte CIRCLE1[] = { B00000000, B00000000, B00011000, B00100100, B00100100, B00011000, B00000000, B00000000};
  24. byte CIRCLE2[] = { B00000000, B00111100, B01000010, B01000010, B01000010, B01000010, B00111100, B00000000};
  25. byte CIRCLE3[] = { B01111110, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B01111110};
  26.  
  27. byte VAR1[] = { B10000000, B10000000, B10000000, B10000000, B10000000, B10000000, B10000000, B10000000};
  28. byte TEMP[8] ;
  29.  
  30. /* we always wait a bit between updates of the display */
  31. unsigned long delaytime = 80;
  32.  
  33. void setup() {
  34.   /*
  35.     The MAX72XX is in power-saving mode on startup,
  36.     we have to do a wakeup call
  37.   */
  38.   lc.shutdown(0, false);
  39.   /* Set the brightness to a medium values */
  40.   lc.setIntensity(0, 8);
  41.   /* and clear the display */
  42.   lc.clearDisplay(0);
  43.  
  44. }
  45.  
  46.  
  47. void matrix(byte PARAM[]) {
  48.   for (int i = 0; i < 8; i++) {
  49.     lc.setRow(0, i, PARAM[i]);
  50.   }
  51. }
  52.  
  53. void loop() {
  54.   memcpy(TEMP, RIGHT, 8);
  55.   for (int j = 8; j >= 0; j--) {
  56.     for (int i = 0; i < 8; i++) {
  57.       TEMP[i] = TEMP[i] << j;
  58.     }
  59.     matrix(TEMP);
  60.     delay(delaytime);
  61.     memcpy(TEMP, RIGHT, 8);
  62.   }
  63.  
  64.   for (int j = 1; j < 8; j++) {
  65.     for (int i = 0; i < 8; i++) {
  66.       TEMP[i] = TEMP[i] >> j;
  67.     }
  68.     matrix(TEMP);
  69.     delay(delaytime);
  70.     memcpy(TEMP, RIGHT, 8);
  71.   }
  72.  
  73.  
  74.  
  75.  
  76.   //  matrix(LEFT);
  77.   //  delay(delaytime);
  78.   //  matrix(RIGHT);
  79.   //  delay(delaytime);
  80.   //  matrix(UP);
  81.   //  delay(delaytime);
  82.   //  matrix(DIAMOND);
  83.   //  delay(delaytime);
  84.   //  matrix(SQUARE);
  85.   //  delay(delaytime);
  86.   //  matrix(SQUARE1);
  87.   //  delay(delaytime);
  88.   //  matrix(SQUARE2);
  89.   //  delay(delaytime);
  90.   //  matrix(SQUARE3);
  91.   //  delay(delaytime);
  92.  
  93.   //    matrix(CIRCLE0);
  94.   //    delay(delaytime);
  95.   //    matrix(CIRCLE1);
  96.   //    delay(delaytime);
  97.   //    matrix(CIRCLE2);
  98.   //    delay(delaytime);
  99.   //    matrix(CIRCLE3);
  100.   //    delay(delaytime);
  101.  
  102.   //  for (int i = 0; i < 4; i++) {
  103.   //    matrix(CIRCLE3);
  104.   //    delay(delaytime);
  105.   //    matrix(CIRCLE2);
  106.   //    delay(delaytime);
  107.   //    matrix(CIRCLE1);
  108.   //    delay(delaytime);
  109.   //  }
  110.   //  lc.clearDisplay(0);
  111.   //  delay(100);
  112. }
Add Comment
Please, Sign In to add comment