Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. // Adafruit_NeoMatrix example for tiled NeoPixel matrices. Scrolls
  2. // 'Howdy' across three 10x8 NeoPixel grids that were created using
  3. // NeoPixel 60 LEDs per meter flex strip.
  4.  
  5. #include <Adafruit_GFX.h>
  6. #include <Adafruit_NeoMatrix.h>
  7. #include <Adafruit_NeoPixel.h>
  8. #include <FastLED.h>
  9.  
  10. #ifndef PSTR
  11. #define PSTR // Make Arduino Due happy
  12. #endif
  13.  
  14. #define PIN 6
  15.  
  16. // MATRIX DECLARATION:
  17. // Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display)
  18. // Parameter 2 = height of each matrix
  19. // Parameter 3 = number of matrices arranged horizontally
  20. // Parameter 4 = number of matrices arranged vertically
  21. // Parameter 5 = pin number (most are valid)
  22. // Parameter 6 = matrix layout flags, add together as needed:
  23. // NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
  24. // Position of the FIRST LED in the FIRST MATRIX; pick two, e.g.
  25. // NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
  26. // NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are
  27. // arranged in horizontal rows or in vertical columns, respectively;
  28. // pick one or the other.
  29. // NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns WITHIN
  30. // EACH MATRIX proceed in the same order, or alternate lines reverse
  31. // direction; pick one.
  32. // NEO_TILE_TOP, NEO_TILE_BOTTOM, NEO_TILE_LEFT, NEO_TILE_RIGHT:
  33. // Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick
  34. // two, e.g. NEO_TILE_TOP + NEO_TILE_LEFT for the top-left corner.
  35. // NEO_TILE_ROWS, NEO_TILE_COLUMNS: the matrices in the OVERALL DISPLAY
  36. // are arranged in horizontal rows or in vertical columns, respectively;
  37. // pick one or the other.
  38. // NEO_TILE_PROGRESSIVE, NEO_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES
  39. // (tiles) in the OVERALL DISPLAY proceed in the same order for every
  40. // line, or alternate lines reverse direction; pick one. When using
  41. // zig-zag order, the orientation of the matrices in alternate rows
  42. // will be rotated 180 degrees (this is normal -- simplifies wiring).
  43. // See example below for these values in action.
  44. // Parameter 7 = pixel type flags, add together as needed:
  45. // NEO_RGB Pixels are wired for RGB bitstream (v1 pixels)
  46. // NEO_GRB Pixels are wired for GRB bitstream (v2 pixels)
  47. // NEO_KHZ400 400 KHz bitstream (e.g. FLORA v1 pixels)
  48. // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
  49.  
  50. // Example with three 10x8 matrices (created using NeoPixel flex strip --
  51. // these grids are not a ready-made product). In this application we'd
  52. // like to arrange the three matrices side-by-side in a wide display.
  53. // The first matrix (tile) will be at the left, and the first pixel within
  54. // that matrix is at the top left. The matrices use zig-zag line ordering.
  55. // There's only one row here, so it doesn't matter if we declare it in row
  56. // or column order. The matrices use 800 KHz (v2) pixels that expect GRB
  57. // color data.
  58. const int panelWidth = 8;
  59. const int panelHeight = 8;
  60.  
  61. Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(panelWidth, panelHeight, 2, 2, PIN,
  62. NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_ZIGZAG +
  63. NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
  64. NEO_GRB + NEO_KHZ800);
  65. const uint8_t kMatrixWidth = 16;
  66. const uint8_t kMatrixHeight = 16;
  67.  
  68. const uint16_t colors[] = {
  69. matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255)
  70. };
  71. void setup() {
  72. Serial.begin(115200);
  73. matrix.begin();
  74. matrix.setTextWrap(false);
  75. matrix.setBrightness(16);
  76. matrix.setTextColor(colors[0]);
  77. }
  78.  
  79. int x = matrix.width();
  80. int pass = 0;
  81.  
  82. void loop() {
  83.  
  84. DrawCircle();
  85.  
  86. DrawSquare(false);
  87. DrawChar();
  88. DrawRainbow();
  89. DrawLove();
  90. x = 0;
  91.  
  92. }
  93. void DrawCircle() {
  94. while (x < matrix.width()) {
  95. matrix.fillScreen(0);
  96. CRGB color1 = CHSV(0, 0, 255);
  97. CRGB color2 = CHSV(0, 0, 125);
  98. CRGB color3 = CHSV(0, 0, 64);
  99. CRGB color4 = CHSV(0, 0, 8);
  100. int _x = kMatrixWidth * 0.5;
  101. int _y = kMatrixHeight * 0.5;
  102. matrix.drawCircle(_x, _y, x - 3, matrix.Color(color4.red, color4.green, color4.blue));
  103. matrix.drawCircle(_x, _y, x - 2, matrix.Color(color3.red, color3.green, color3.blue));
  104. matrix.drawCircle(_x, _y, x - 1, matrix.Color(color2.red, color2.green, color2.blue));
  105. matrix.drawCircle(_x, _y, x, matrix.Color(color1.red, color1.green, color1.blue));
  106. matrix.drawCircle(_x, _y, x + 1, matrix.Color(color2.red, color2.green, color2.blue));
  107. matrix.drawCircle(_x, _y, x + 2, matrix.Color(color3.red, color3.green, color3.blue));
  108. matrix.drawCircle(_x, _y, x + 3, matrix.Color(color4.red, color4.green, color4.blue));
  109. matrix.show();
  110. x++;
  111. delay(100);
  112. }
  113. x = 0;
  114. }
  115.  
  116. void DrawSquare(boolean isFill) {
  117. while (x < matrix.width()) {
  118. matrix.fillScreen(0);
  119. CRGB color1 = CHSV(0, 0, 255);
  120. CRGB color2 = CHSV(0, 0, 125);
  121. CRGB color3 = CHSV(0, 0, 64);
  122. CRGB color4 = CHSV(0, 0, 8);
  123. int _x = kMatrixWidth * 0.5;
  124. int _y = kMatrixHeight * 0.5;
  125. int half = (x / 2.0);
  126. if (isFill) {
  127. matrix.fillRect(_x - half, _y - half, x, x, matrix.Color(color1.red, color1.green, color1.blue));
  128. } else {
  129. matrix.drawRect(_x - half, _y - half, x, x, matrix.Color(color1.red, color1.green, color1.blue));
  130. }
  131. matrix.show();
  132. x++;
  133. delay(100);
  134. }
  135. x = 0;
  136. }
  137.  
  138. void DrawChar() {
  139. x = 0;
  140. matrix.setTextColor(matrix.Color(255, 255, 255));
  141. matrix.setTextSize(2);
  142. char message[64] = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  143. while (x < 63) {
  144.  
  145. matrix.fillScreen(0);
  146. int _x = kMatrixWidth * 0.5;
  147. int _y = kMatrixHeight * 0.5;
  148. matrix.setCursor(3, 1);
  149. matrix.print(String(message[x]));
  150. x++;
  151.  
  152. matrix.show();
  153. delay(500);
  154. }
  155. x = 0;
  156. }
  157.  
  158. void DrawRainbow() {
  159. x = 0;
  160. while (x < matrix.width() * 2) {
  161. uint32_t ms = millis();
  162. int32_t yHueDelta32 = ((int32_t)cos16( ms * (27 / 1) ) * (350 / kMatrixWidth));
  163. int32_t xHueDelta32 = ((int32_t)cos16( ms * (39 / 1) ) * (310 / kMatrixHeight));
  164. DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768);
  165. matrix.show();
  166. x++;
  167. delay(50);
  168. }
  169.  
  170. }
  171.  
  172. void DrawLove() {
  173. x = 0;
  174. matrix.setTextColor(matrix.Color(255, 255, 255));
  175. matrix.setTextSize(1);
  176.  
  177. while (x < matrix.width()) {
  178.  
  179. matrix.fillScreen(0);
  180. int _x = kMatrixWidth * 0.5;
  181. int _y = kMatrixHeight * 0.5;
  182. matrix.setCursor(0, 0);
  183. matrix.print(String("L"));
  184. matrix.setCursor(8, 0);
  185. matrix.print(String("O"));
  186. matrix.setCursor(0, 8);
  187. matrix.print(String("V"));
  188. matrix.setCursor(8, 8);
  189. matrix.print(String("E"));
  190. x++;
  191.  
  192. matrix.show();
  193. delay(500);
  194. }
  195. x = 0;
  196. }
  197.  
  198.  
  199. void DrawOneFrame( byte startHue8, int8_t yHueDelta8, int8_t xHueDelta8)
  200. {
  201. byte lineStartHue = startHue8;
  202. for ( byte y = 0; y < kMatrixHeight; y++) {
  203. lineStartHue += yHueDelta8;
  204. byte pixelHue = lineStartHue;
  205. for ( byte x = 0; x < kMatrixWidth; x++) {
  206. pixelHue += xHueDelta8;
  207.  
  208. CRGB color = CHSV( pixelHue, 255, 255);
  209. matrix.drawPixel(x, y, matrix.Color(color.red , color.green, color.blue));
  210. }
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement