WeatherMatrix.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <FastLED.h>
  2. #define LED_PIN 13
  3. #define COLOR_ORDER GRB
  4. #define CHIPSET WS2811
  5. #define BRIGHTNESS 10
  6. // Params for width and height
  7. const uint8_t kMatrixWidth = 16;
  8. const uint8_t kMatrixHeight = 16;
  9. uint16_t XY( uint8_t x, uint8_t y)
  10. {
  11. uint16_t i;
  12. if ( x & 0x01) {
  13. i = kMatrixHeight * (kMatrixWidth - (x + 1)) + y;
  14. } else {
  15. i = kMatrixHeight * (kMatrixWidth - x) - (y + 1);
  16. }
  17. return i;
  18. }
  19. #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
  20. CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
  21. CRGB* const leds( leds_plus_safety_pixel + 1);
  22. uint16_t XYsafe( uint8_t x, uint8_t y)
  23. {
  24. if ( x >= kMatrixWidth) return -1;
  25. if ( y >= kMatrixHeight) return -1;
  26. return XY(x, y);
  27. }
  28. uint8_t sun_yx[16][16] = {
  29. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  30. {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  31. {0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0},
  32. {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  33. {1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1},
  34. {0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0},
  35. {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
  36. {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0},
  37. {0, 1, 1, 0, 1, 0,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 1, 1, 1, 1, 1, 0, 0},
  59. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  60. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  61. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  62. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  63. };
  64. void DrawFrame(uint8_t arr[][16])
  65. {
  66. for (int i = 0; i < 16; i++) {
  67. for (int j = 0; j < 16; j++) {
  68. uint8_t elem = arr[i][j];
  69. if (elem == 1) {
  70. leds[ XYsafe(i, j)] = CRGB::Yellow;
  71. }
  72. }
  73. }
  74. }
  75. void loop()
  76. {
  77. DrawFrame(sun_yx);
  78. FastLED.show();
  79. delay(3000);
  80. FastLED.clear();
  81. DrawFrame(cloud_yx);
  82. FastLED.show();
  83. delay(3000);
  84. FastLED.clear();
  85. }
  86. void setup() {
  87. Serial.begin(9600);
  88. FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
  89. FastLED.setBrightness( BRIGHTNESS );
  90. }