Guest User

LED

a guest
Jan 9th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. #include <FastLED.h>
  2. #include <FastLED_GFX.h>
  3. #include <LEDMatrix.h>
  4.  
  5. // Change the next defines to match your matrix type and size
  6. #define DATA_PIN 5
  7.  
  8. #define COLOR_ORDER GRB
  9. #define CHIPSET WS2811
  10.  
  11. // initial matrix layout (to get led strip index by x/y)
  12. #define MATRIX_WIDTH 16
  13. #define MATRIX_HEIGHT 16
  14. #define MATRIX_TYPE VERTICAL_ZIGZAG_MATRIX
  15. #define MATRIX_SIZE (MATRIX_WIDTH*MATRIX_HEIGHT)
  16. #define NUMPIXELS MATRIX_SIZE
  17. #define BRIGHTNESS 5
  18.  
  19. // create our matrix based on matrix definition
  20. cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
  21.  
  22. void setup() {
  23. // initial FastLED by using CRGB led source from our matrix class
  24. FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds[0], leds.Size()).setCorrection(TypicalLEDStrip);
  25. FastLED.setBrightness(BRIGHTNESS);
  26. FastLED.clear(true);
  27.  
  28. //If Panel shows code works
  29. FastLED.showColor(CRGB::Green);
  30. delay(1000);
  31. FastLED.showColor(CRGB::Red);
  32. delay(1000);
  33. FastLED.showColor(CRGB::Blue);
  34. delay(1000);
  35. FastLED.showColor(CRGB::White);
  36. delay(1000);
  37. FastLED.clear(true);
  38. }
  39.  
  40. void loop() {
  41. int16_t sx, sy, x, y, xc, yc, r;
  42. uint8_t h;
  43. for (x = 0; x < leds.Size(); x++)
  44. {
  45. //drawTriangle(2, 1, 8, 1, 8, 7, CRGB::Red);
  46. //drawNorwayFlag();
  47. // FastLED.show();
  48. // delay(1000);
  49. // drawJapFlag();
  50. // FastLED.show();
  51. // delay(1000);
  52. // drawQuadrilateral(0,0,0,5,5,5,5,0, CRGB::Red);
  53. // drawFace();
  54. drawPowerUp();
  55. }
  56. FastLED.show();
  57. }
  58.  
  59.  
  60. void drawNorwayFlag() {
  61. int16_t x = (leds.Width() / 4);
  62. int16_t y = (leds.Height() / 2) - 2;
  63. leds.DrawFilledRectangle(0, 0, x, y, CRGB(255, 255, 255));
  64. leds.DrawFilledRectangle(0, 0, x - 1, y - 1, CRGB(255, 0, 0));
  65. leds.DrawFilledRectangle(x + 3, 0, leds.Width() - 1, y, CRGB(255, 255, 255));
  66. leds.DrawFilledRectangle(x + 4, 0, leds.Width() - 1, y - 1, CRGB(255, 0, 0));
  67. leds.DrawFilledRectangle(0, y + 3, x, leds.Height() - 1, CRGB(255, 255, 255));
  68. leds.DrawFilledRectangle(0, y + 4, x - 1, leds.Height() - 1, CRGB(255, 0, 0));
  69. leds.DrawFilledRectangle(x + 3, y + 3, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255));
  70. leds.DrawFilledRectangle(x + 4, y + 4, leds.Width() - 1, leds.Height() - 1, CRGB(255, 0, 0));
  71. leds.DrawLine(0, y + 1, leds.Width() - 1, y + 1, CRGB(0, 0, 255));
  72. leds.DrawLine(0, y + 2, leds.Width() - 1, y + 2, CRGB(0, 0, 255));
  73. leds.DrawLine(x + 1, 0, x + 1, leds.Height() - 1, CRGB(0, 0, 255));
  74. leds.DrawLine(x + 2, 0, x + 2, leds.Height() - 1, CRGB(0, 0, 255));
  75. }
  76.  
  77. void drawJapFlag() {
  78. leds.DrawFilledRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB::White);
  79. uint16_t r = min((leds.Width() - 1) / 2, (leds.Height() - 1) / 2) - 1;
  80. leds.DrawFilledCircle((leds.Width() - 1) / 2, (leds.Height() - 1) / 2, r, CRGB::Red);
  81. }
  82.  
  83. void drawPowerUp() {
  84. leds.drawPixel(6, 0, CRGB::Red);
  85. }
  86.  
  87. void drawFace() {
  88. int16_t x = leds.Width() / 2;
  89. int16_t y = leds.Height() / 2;
  90. leds.DrawCircle(x, y, 6, CRGB::Purple);
  91. leds.DrawCircle(5, 6, 1, CRGB::Blue);
  92. leds.DrawCircle(10, 6, 1, CRGB::Blue);
  93. leds.HorizontalMirror();
  94. leds.DrawRectangle(5, 10, 11, 11, CRGB::Green);
  95. }
  96.  
  97. //Function to draw triangles
  98. void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color) {
  99. leds.DrawLine(x0, y0, x1, y1, color);
  100. leds.DrawLine(x1, y1, x2, y2, color);
  101. leds.DrawLine(x2, y2, x0, y0, color);
  102. }
  103.  
  104. //Function to draw custom quadrilaterals
  105. void drawQuadrilateral(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, CRGB color) {
  106. leds.DrawLine(x0, y0, x1, y1, color);
  107. leds.DrawLine(x1, y1, x2, y2, color);
  108. leds.DrawLine(x2, y2, x3, y3, color);
  109. leds.DrawLine(x3, y3, x0, y0, color);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment