Prechádzať zdrojové kódy

feat(core): add base functionality

sezuisa 10 mesiacov pred
rodič
commit
94b085a8d2
1 zmenil súbory, kde vykonal 105 pridanie a 0 odobranie
  1. 105 0
      WeatherMatrix.ino

+ 105 - 0
WeatherMatrix.ino

@@ -0,0 +1,105 @@
+#include <FastLED.h>
+
+#define LED_PIN  13
+
+#define COLOR_ORDER GRB
+#define CHIPSET     WS2811
+
+#define BRIGHTNESS 10
+
+// Params for width and height
+const uint8_t kMatrixWidth = 16;
+const uint8_t kMatrixHeight = 16;
+
+uint16_t XY( uint8_t x, uint8_t y)
+{
+  uint16_t i;
+  if ( x & 0x01) {
+    i = kMatrixHeight * (kMatrixWidth - (x + 1)) + y;
+  } else {
+    i = kMatrixHeight * (kMatrixWidth - x) - (y + 1);
+  }
+  return i;
+}
+
+#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
+CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
+CRGB* const leds( leds_plus_safety_pixel + 1);
+
+uint16_t XYsafe( uint8_t x, uint8_t y)
+{
+  if ( x >= kMatrixWidth) return -1;
+  if ( y >= kMatrixHeight) return -1;
+  return XY(x, y);
+}
+
+uint8_t sun_yx[16][16] = {
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
+  {0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0},
+  {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
+  {1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1},
+  {0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0},
+  {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
+  {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0},
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1, 1, 1, 1, 1, 0, 0},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+};
+
+void DrawFrame(uint8_t arr[][16])
+{
+  for (int i = 0; i < 16; i++) {
+    for (int j = 0; j < 16; j++) {
+      uint8_t elem = arr[i][j];
+      if (elem == 1) {
+        leds[ XYsafe(i, j)]  = CRGB::Yellow;
+      }
+    }
+  }
+}
+
+void loop()
+{
+  DrawFrame(sun_yx);
+  FastLED.show();
+  delay(3000);
+  FastLED.clear();
+  DrawFrame(cloud_yx);
+  FastLED.show();
+  delay(3000);
+  FastLED.clear();
+}
+
+
+
+
+void setup() {
+  Serial.begin(9600);
+  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
+  FastLED.setBrightness( BRIGHTNESS );
+}