#include #define LED_PIN 0 #define COLOR_ORDER GRB #define CHIPSET WS2811 #define BRIGHTNESS 10 // networking and json String apiUrl; int status = WL_IDLE_STATUS; int connectWiFi() { WiFi.begin("Wokwi-GUEST", "", 6); while (WiFi.status() != WL_CONNECTED) { delay(100); } return WiFi.status(); } String buildAPIUrl (double lat, double lon, const String& apiKey) { const String latStr(lat, 4); const String lonStr(lon, 4); return String("https://api.openweathermap.org/data/2.5/weather?lat=" + latStr + "&lon=" + lonStr + "&appid=" + apiKey); } // 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}, {0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,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 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); // weather api const float lat = 48.9517; const float lon = 10.1703; const String apiKey = "e471293b25fdb6697c0a862f2695df5f"; apiUrl = buildAPIUrl(lat, lon, apiKey); connectWiFi(); if (WiFi.status() != WL_CONNECTED) { Serial.println(WiFi.status()); } HTTPClient http; http.begin(apiUrl); int respCode = http.GET(); JsonDocument payload; if(respCode > 0){ const String response = http.getString(); deserializeJson(payload, response); Serial.println(payload.size()); } else { Serial.print("error "); Serial.println(respCode); } FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalSMD5050); FastLED.setBrightness( BRIGHTNESS ); }