Advertisement
raiffm21

Matrix 1

Jan 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. #include <FrequencyTimer2.h>
  2. #define SPACE { \
  3. {0, 0, 0, 0, 0, 0, 0, 0}, \
  4. {0, 0, 0, 0, 0, 0, 0, 0}, \
  5. {0, 0, 0, 0, 0, 0, 0, 0}, \
  6. {0, 0, 0, 0, 0, 0, 0, 0}, \
  7. {0, 0, 0, 0, 0, 0, 0, 0}, \
  8. {0, 0, 0, 0, 0, 0, 0, 0}, \
  9. {0, 0, 0, 0, 0, 0, 0, 0}, \
  10. {0, 0, 0, 0, 0, 0, 0, 0} \
  11. }
  12. #define H { \
  13. {0, 1, 0, 0, 0, 0, 1, 0}, \
  14. {0, 1, 0, 0, 0, 0, 1, 0}, \
  15. {0, 1, 0, 0, 0, 0, 1, 0}, \
  16. {0, 1, 1, 1, 1, 1, 1, 0}, \
  17. {0, 1, 0, 0, 0, 0, 1, 0}, \
  18. {0, 1, 0, 0, 0, 0, 1, 0}, \
  19. {0, 1, 0, 0, 0, 0, 1, 0}, \
  20. {0, 1, 0, 0, 0, 0, 1, 0} \
  21. }
  22. #define E { \
  23. {0, 1, 1, 1, 1, 1, 1, 0}, \
  24. {0, 1, 0, 0, 0, 0, 0, 0}, \
  25. {0, 1, 0, 0, 0, 0, 0, 0}, \
  26. {0, 1, 1, 1, 1, 1, 1, 0}, \
  27. {0, 1, 0, 0, 0, 0, 0, 0}, \
  28. {0, 1, 0, 0, 0, 0, 0, 0}, \
  29. {0, 1, 0, 0, 0, 0, 0, 0}, \
  30. {0, 1, 1, 1, 1, 1, 1, 0} \
  31. }
  32. #define L { \
  33. {0, 1, 0, 0, 0, 0, 0, 0}, \
  34. {0, 1, 0, 0, 0, 0, 0, 0}, \
  35. {0, 1, 0, 0, 0, 0, 0, 0}, \
  36. {0, 1, 0, 0, 0, 0, 0, 0}, \
  37. {0, 1, 0, 0, 0, 0, 0, 0}, \
  38. {0, 1, 0, 0, 0, 0, 0, 0}, \
  39. {0, 1, 0, 0, 0, 0, 0, 0}, \
  40. {0, 1, 1, 1, 1, 1, 1, 0} \
  41. }
  42. #define O { \
  43. {0, 0, 0, 1, 1, 0, 0, 0}, \
  44. {0, 0, 1, 0, 0, 1, 0, 0}, \
  45. {0, 1, 0, 0, 0, 0, 1, 0}, \
  46. {0, 1, 0, 0, 0, 0, 1, 0}, \
  47. {0, 1, 0, 0, 0, 0, 1, 0}, \
  48. {0, 1, 0, 0, 0, 0, 1, 0}, \
  49. {0, 0, 1, 0, 0, 1, 0, 0}, \
  50. {0, 0, 0, 1, 1, 0, 0, 0} \
  51. }
  52. #define C { \
  53. {0, 0, 0, 0, 0, 0, 0, 0}, \
  54. {0, 0, 0, 0, 0, 0, 0, 0}, \
  55. {0, 0, 0, 0, 0, 0, 0, 0}, \
  56. {0, 0, 0, 0, 0, 0, 0, 0}, \
  57. {0, 0, 0, 0, 0, 0, 0, 0}, \
  58. {0, 0, 1, 0, 0, 0, 0, 0}, \
  59. {0, 0, 0, 1, 0, 0, 0, 0}, \
  60. {0, 0, 1, 0, 0, 0, 0, 0} \
  61. }
  62. #define M { \
  63. {0, 1, 0, 0, 0, 0, 1, 0}, \
  64. {0, 1, 1, 0, 0, 1, 1, 0}, \
  65. {0, 1, 0, 1, 1, 0, 1, 0}, \
  66. {0, 1, 0, 0, 0, 0, 1, 0}, \
  67. {0, 1, 0, 0, 0, 0, 1, 0}, \
  68. {0, 1, 0, 0, 0, 0, 1, 0}, \
  69. {0, 1, 0, 0, 0, 0, 1, 0}, \
  70. {0, 1, 0, 0, 0, 0, 1, 0} \
  71. }
  72. #define A { \
  73. {0, 0, 0, 1, 1, 0, 0, 0}, \
  74. {0, 0, 1, 0, 0, 1, 0, 0}, \
  75. {0, 1, 0, 0, 0, 0, 1, 0}, \
  76. {0, 1, 0, 0, 0, 0, 1, 0}, \
  77. {0, 1, 1, 1, 1, 1, 1, 0}, \
  78. {0, 1, 0, 0, 0, 0, 1, 0}, \
  79. {0, 1, 0, 0, 0, 0, 1, 0}, \
  80. {0, 1, 0, 0, 0, 0, 1, 0} \
  81. }
  82. #define N { \
  83. {0, 1, 0, 0, 0, 0, 1, 0}, \
  84. {0, 1, 1, 0, 0, 0, 1, 0}, \
  85. {0, 1, 0, 0, 0, 0, 1, 0}, \
  86. {0, 1, 0, 1, 0, 0, 1, 0}, \
  87. {0, 1, 0, 0, 1, 0, 1, 0}, \
  88. {0, 1, 0, 0, 0, 0, 1, 0}, \
  89. {0, 1, 0, 0, 0, 1, 1, 0}, \
  90. {0, 1, 0, 0, 0, 0, 1, 0} \
  91. }
  92. #define D { \
  93. {0, 1, 0, 0, 0, 0, 0, 0}, \
  94. {0, 1, 1, 1, 1, 0, 1, 0}, \
  95. {0, 1, 0, 0, 0, 0, 1, 0}, \
  96. {0, 1, 0, 0, 0, 0, 1, 0}, \
  97. {0, 1, 0, 0, 0, 0, 1, 0}, \
  98. {0, 1, 0, 0, 0, 0, 1, 0}, \
  99. {0, 1, 1, 1, 1, 1, 1, 0}, \
  100. {0, 1, 0, 0, 0, 0, 0, 0} \
  101. }
  102. #define Y { \
  103. {0, 1, 0, 0, 0, 0, 1, 0}, \
  104. {0, 0, 1, 0, 0, 1, 0, 0}, \
  105. {0, 0, 0, 1, 1, 0, 0, 0}, \
  106. {0, 0, 0, 0, 1, 0, 0, 0}, \
  107. {0, 0, 0, 0, 1, 0, 0, 0}, \
  108. {0, 0, 0, 0, 1, 0, 0, 0}, \
  109. {0, 0, 0, 0, 1, 0, 0, 0}, \
  110. {0, 0, 0, 0, 1, 0, 0, 0} \
  111. }
  112. byte col = 0;
  113. byte leds[8][8];
  114. // pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
  115. int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
  116. // col[xx] of leds = pin yy on led matrix
  117. int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};
  118. // row[xx] of leds = pin yy on led matrix
  119. int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};
  120. const int numPatterns = 12;
  121. byte patterns[numPatterns][8][8] = {
  122. SPACE,H,E,L,L,O,C,M,A,N,D,Y
  123. };
  124. int pattern = 0;
  125. void setup() {
  126. // sets the pins as output
  127. for (int i = 1; i <= 16; i++) {
  128. pinMode(pins[i], OUTPUT);
  129. }
  130. // set up cols and rows
  131. for (int i = 1; i <= 8; i++) {
  132. digitalWrite(cols[i - 1], HIGH);
  133. }
  134. for (int i = 1; i <= 8; i++) {
  135. digitalWrite(rows[i - 1], HIGH);
  136. }
  137. clearLeds();
  138. // Turn off toggling of pin 11
  139. FrequencyTimer2::disable();
  140. // Set refresh rate (interrupt timeout period)
  141. FrequencyTimer2::setPeriod(2000);
  142. // Set interrupt routine to be called
  143. FrequencyTimer2::setOnOverflow(display);
  144. setPattern(pattern);
  145. }
  146. void loop() {
  147. pattern = ++pattern % numPatterns;
  148. slidePattern(pattern, 60);
  149. }
  150. void clearLeds() {
  151. // Clear display array
  152. for (int i = 0; i < 8; i++) {
  153. for (int j = 0; j < 8; j++) {
  154. leds[i][j] = 0;
  155. }
  156. }
  157. }
  158. void setPattern(int pattern) {
  159. for (int i = 0; i < 8; i++) {
  160. for (int j = 0; j < 8; j++) {
  161. leds[i][j] = patterns[pattern][i][j];
  162. }
  163. }
  164. }
  165. void slidePattern(int pattern, int del) {
  166. for (int l = 0; l < 8; l++) {
  167. for (int i = 0; i < 7; i++) {
  168. for (int j = 0; j < 8; j++) {
  169. leds[j][i] = leds[j][i+1];
  170. }
  171. }
  172. for (int j = 0; j < 8; j++) {
  173. leds[j][7] = patterns[pattern][j][0 + l];
  174. }
  175. delay(del);
  176. }
  177. }
  178. // Interrupt routine
  179. void display() {
  180. digitalWrite(cols[col], HIGH); // Turn whole previous column off
  181. col++;
  182. if (col == 8) {
  183. col = 0;
  184. }
  185. for (int row = 0; row < 8; row++) {
  186. if (leds[col][7 - row] == 1) {
  187. digitalWrite(rows[row], HIGH); // Turn on this led
  188. }
  189. else {
  190. digitalWrite(rows[row], LOW); // Turn off this led
  191. }
  192. }
  193. digitalWrite(cols[col], LOW); // Turn whole column on at once (for equal lighting times)
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement