PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LCDemoMatrix.ino 4.0KB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //We always have to include the library
  2. #include "LedControl.h"
  3. /*
  4. Now we need a LedControl to work with.
  5. ***** These pin numbers will probably not work with your hardware *****
  6. pin 12 is connected to the DataIn
  7. pin 11 is connected to the CLK
  8. pin 10 is connected to LOAD
  9. We have only a single MAX72XX.
  10. */
  11. LedControl lc=LedControl(12,11,10,1);
  12. /* we always wait a bit between updates of the display */
  13. unsigned long delaytime=100;
  14. void setup() {
  15. /*
  16. The MAX72XX is in power-saving mode on startup,
  17. we have to do a wakeup call
  18. */
  19. lc.shutdown(0,false);
  20. /* Set the brightness to a medium values */
  21. lc.setIntensity(0,8);
  22. /* and clear the display */
  23. lc.clearDisplay(0);
  24. }
  25. /*
  26. This method will display the characters for the
  27. word "Arduino" one after the other on the matrix.
  28. (you need at least 5x7 leds to see the whole chars)
  29. */
  30. void writeArduinoOnMatrix() {
  31. /* here is the data for the characters */
  32. byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
  33. byte r[5]={B00111110,B00010000,B00100000,B00100000,B00010000};
  34. byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
  35. byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
  36. byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};
  37. byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
  38. byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};
  39. /* now display them one by one with a small delay */
  40. lc.setRow(0,0,a[0]);
  41. lc.setRow(0,1,a[1]);
  42. lc.setRow(0,2,a[2]);
  43. lc.setRow(0,3,a[3]);
  44. lc.setRow(0,4,a[4]);
  45. delay(delaytime);
  46. lc.setRow(0,0,r[0]);
  47. lc.setRow(0,1,r[1]);
  48. lc.setRow(0,2,r[2]);
  49. lc.setRow(0,3,r[3]);
  50. lc.setRow(0,4,r[4]);
  51. delay(delaytime);
  52. lc.setRow(0,0,d[0]);
  53. lc.setRow(0,1,d[1]);
  54. lc.setRow(0,2,d[2]);
  55. lc.setRow(0,3,d[3]);
  56. lc.setRow(0,4,d[4]);
  57. delay(delaytime);
  58. lc.setRow(0,0,u[0]);
  59. lc.setRow(0,1,u[1]);
  60. lc.setRow(0,2,u[2]);
  61. lc.setRow(0,3,u[3]);
  62. lc.setRow(0,4,u[4]);
  63. delay(delaytime);
  64. lc.setRow(0,0,i[0]);
  65. lc.setRow(0,1,i[1]);
  66. lc.setRow(0,2,i[2]);
  67. lc.setRow(0,3,i[3]);
  68. lc.setRow(0,4,i[4]);
  69. delay(delaytime);
  70. lc.setRow(0,0,n[0]);
  71. lc.setRow(0,1,n[1]);
  72. lc.setRow(0,2,n[2]);
  73. lc.setRow(0,3,n[3]);
  74. lc.setRow(0,4,n[4]);
  75. delay(delaytime);
  76. lc.setRow(0,0,o[0]);
  77. lc.setRow(0,1,o[1]);
  78. lc.setRow(0,2,o[2]);
  79. lc.setRow(0,3,o[3]);
  80. lc.setRow(0,4,o[4]);
  81. delay(delaytime);
  82. lc.setRow(0,0,0);
  83. lc.setRow(0,1,0);
  84. lc.setRow(0,2,0);
  85. lc.setRow(0,3,0);
  86. lc.setRow(0,4,0);
  87. delay(delaytime);
  88. }
  89. /*
  90. This function lights up a some Leds in a row.
  91. The pattern will be repeated on every row.
  92. The pattern will blink along with the row-number.
  93. row number 4 (index==3) will blink 4 times etc.
  94. */
  95. void rows() {
  96. for(int row=0;row<8;row++) {
  97. delay(delaytime);
  98. lc.setRow(0,row,B10100000);
  99. delay(delaytime);
  100. lc.setRow(0,row,(byte)0);
  101. for(int i=0;i<row;i++) {
  102. delay(delaytime);
  103. lc.setRow(0,row,B10100000);
  104. delay(delaytime);
  105. lc.setRow(0,row,(byte)0);
  106. }
  107. }
  108. }
  109. /*
  110. This function lights up a some Leds in a column.
  111. The pattern will be repeated on every column.
  112. The pattern will blink along with the column-number.
  113. column number 4 (index==3) will blink 4 times etc.
  114. */
  115. void columns() {
  116. for(int col=0;col<8;col++) {
  117. delay(delaytime);
  118. lc.setColumn(0,col,B10100000);
  119. delay(delaytime);
  120. lc.setColumn(0,col,(byte)0);
  121. for(int i=0;i<col;i++) {
  122. delay(delaytime);
  123. lc.setColumn(0,col,B10100000);
  124. delay(delaytime);
  125. lc.setColumn(0,col,(byte)0);
  126. }
  127. }
  128. }
  129. /*
  130. This function will light up every Led on the matrix.
  131. The led will blink along with the row-number.
  132. row number 4 (index==3) will blink 4 times etc.
  133. */
  134. void single() {
  135. for(int row=0;row<8;row++) {
  136. for(int col=0;col<8;col++) {
  137. delay(delaytime);
  138. lc.setLed(0,row,col,true);
  139. delay(delaytime);
  140. for(int i=0;i<col;i++) {
  141. lc.setLed(0,row,col,false);
  142. delay(delaytime);
  143. lc.setLed(0,row,col,true);
  144. delay(delaytime);
  145. }
  146. }
  147. }
  148. }
  149. void loop() {
  150. writeArduinoOnMatrix();
  151. rows();
  152. columns();
  153. single();
  154. }