hendriawan

matrix max7219 test

Feb 7th, 2019
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  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 = 1000;
  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.  
  55. memcpy(TEMP, UP, 8);
  56. TEMP[0] = TEMP[1];
  57. TEMP[1] = TEMP[2];
  58. TEMP[2] = TEMP[3];
  59. TEMP[3] = TEMP[4];
  60. TEMP[4] = TEMP[5];
  61. TEMP[5] = TEMP[6];
  62. TEMP[6] = TEMP[7];
  63. TEMP[7] = 0;
  64.  
  65. matrix(TEMP);
  66. delay(delaytime);
  67.  
  68. TEMP[0] = TEMP[1];
  69. TEMP[1] = TEMP[2];
  70. TEMP[2] = TEMP[3];
  71. TEMP[3] = TEMP[4];
  72. TEMP[4] = TEMP[5];
  73. TEMP[5] = TEMP[6];
  74. TEMP[6] = TEMP[7];
  75. TEMP[7] = 0;
  76.  
  77. matrix(TEMP);
  78. delay(delaytime);
  79.  
  80. TEMP[0] = TEMP[1];
  81. TEMP[1] = TEMP[2];
  82. TEMP[2] = TEMP[3];
  83. TEMP[3] = TEMP[4];
  84. TEMP[4] = TEMP[5];
  85. TEMP[5] = TEMP[6];
  86. TEMP[6] = TEMP[7];
  87. TEMP[7] = 0;
  88.  
  89. matrix(TEMP);
  90. delay(delaytime);
  91.  
  92. TEMP[0] = TEMP[1];
  93. TEMP[1] = TEMP[2];
  94. TEMP[2] = TEMP[3];
  95. TEMP[3] = TEMP[4];
  96. TEMP[4] = TEMP[5];
  97. TEMP[5] = TEMP[6];
  98. TEMP[6] = TEMP[7];
  99. TEMP[7] = 0;
  100.  
  101. matrix(TEMP);
  102. delay(delaytime);
  103.  
  104. TEMP[0] = TEMP[1];
  105. TEMP[1] = TEMP[2];
  106. TEMP[2] = TEMP[3];
  107. TEMP[3] = TEMP[4];
  108. TEMP[4] = TEMP[5];
  109. TEMP[5] = TEMP[6];
  110. TEMP[6] = TEMP[7];
  111. TEMP[7] = 0;
  112.  
  113. matrix(TEMP);
  114. delay(delaytime);
  115.  
  116. TEMP[0] = TEMP[1];
  117. TEMP[1] = TEMP[2];
  118. TEMP[2] = TEMP[3];
  119. TEMP[3] = TEMP[4];
  120. TEMP[4] = TEMP[5];
  121. TEMP[5] = TEMP[6];
  122. TEMP[6] = TEMP[7];
  123. TEMP[7] = 0;
  124.  
  125. matrix(TEMP);
  126. delay(delaytime);
  127.  
  128. // memcpy(TEMP, UP, 8);
  129. // for (int i = 0; i < 7; i++) {
  130. // for (int i = 0; i < 7; i++) {
  131. // TEMP[i] = TEMP[i + 1];
  132. // }
  133. // TEMP[7] = 0;
  134. // matrix(TEMP);
  135. // delay(delaytime);
  136. // }
  137.  
  138. // memcpy(TEMP, UP, 8);
  139. // TEMP[7] = TEMP[6];
  140. // TEMP[6] = TEMP[5];
  141. // TEMP[5] = TEMP[4];
  142. // TEMP[4] = TEMP[3];
  143. // TEMP[3] = TEMP[2];
  144. // TEMP[2] = TEMP[1];
  145. // TEMP[1] = TEMP[0];
  146. // TEMP[0] = 0;
  147. // matrix(TEMP);
  148. // delay(delaytime);
  149. // while (1);
  150.  
  151.  
  152.  
  153.  
  154. // memcpy(TEMP, RIGHT, 8);
  155. // for (int j = 8; j >= 0; j--) {
  156. // for (int i = 0; i < 8; i++) {
  157. // TEMP[i] = TEMP[i] << j;
  158. // }
  159. // matrix(TEMP);
  160. // delay(delaytime);
  161. // memcpy(TEMP, RIGHT, 8);
  162. // }
  163. //
  164. // for (int j = 1; j < 8; j++) {
  165. // for (int i = 0; i < 8; i++) {
  166. // TEMP[i] = TEMP[i] >> j;
  167. // }
  168. // matrix(TEMP);
  169. // delay(delaytime);
  170. // memcpy(TEMP, RIGHT, 8);
  171. // }
  172.  
  173.  
  174.  
  175.  
  176. // matrix(LEFT);
  177. // delay(delaytime);
  178. // matrix(RIGHT);
  179. // delay(delaytime);
  180. // matrix(UP);
  181. // delay(delaytime);
  182. // matrix(DIAMOND);
  183. // delay(delaytime);
  184. // matrix(SQUARE);
  185. // delay(delaytime);
  186. // matrix(SQUARE1);
  187. // delay(delaytime);
  188. // matrix(SQUARE2);
  189. // delay(delaytime);
  190. // matrix(SQUARE3);
  191. // delay(delaytime);
  192.  
  193. // matrix(CIRCLE0);
  194. // delay(delaytime);
  195. // matrix(CIRCLE1);
  196. // delay(delaytime);
  197. // matrix(CIRCLE2);
  198. // delay(delaytime);
  199. // matrix(CIRCLE3);
  200. // delay(delaytime);
  201.  
  202. // for (int i = 0; i < 4; i++) {
  203. // matrix(CIRCLE3);
  204. // delay(delaytime);
  205. // matrix(CIRCLE2);
  206. // delay(delaytime);
  207. // matrix(CIRCLE1);
  208. // delay(delaytime);
  209. // }
  210. // lc.clearDisplay(0);
  211. // delay(100);
  212. }
Advertisement
Add Comment
Please, Sign In to add comment