Untitled
unknown
plain_text
a year ago
3.2 kB
14
Indexable
#include <FastLED.h>
#define NUM_LEDS 60 // Adjust based on your LED strip
#define LED_PIN 6 // Adjust based on your setup
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
uint8_t gHue = 0;
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(96);
Serial.begin(9600);
}
void clearLEDs() {
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
void sunnyDay() {
fill_solid(leds, NUM_LEDS, CRGB::Yellow);
FastLED.show();
delay(50);
}
void clearNight() {
fill_solid(leds, NUM_LEDS, CRGB::Navy);
FastLED.show();
delay(50);
}
void cloudyEffect(bool isDay) {
CRGB baseColor = isDay ? CRGB::White : CRGB::DarkBlue;
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = baseColor;
leds[i].fadeToBlackBy(random(100));
}
FastLED.show();
delay(100);
}
void rainEffect(uint8_t intensity) {
clearLEDs();
for(int i = 0; i < intensity; i++) {
int pos = random(NUM_LEDS);
leds[pos] = CRGB::Blue;
}
FastLED.show();
delay(50);
}
void snowEffect(uint8_t intensity) {
clearLEDs();
for(int i = 0; i < intensity; i++) {
int pos = random(NUM_LEDS);
leds[pos] = CRGB::White;
}
FastLED.show();
delay(100);
}
void thunderEffect() {
if(random8() < 20) {
fill_solid(leds, NUM_LEDS, CRGB::White);
FastLED.show();
delay(50);
clearLEDs();
FastLED.show();
}
}
void displayWeather(int code, bool isDay) {
switch(code) {
case 1000: // Sunny/Clear
isDay ? sunnyDay() : clearNight();
break;
case 1003: // Partly cloudy
case 1006: // Cloudy
case 1009: // Overcast
cloudyEffect(isDay);
break;
case 1030: // Mist
case 1135: // Fog
case 1147: // Freezing fog
fill_solid(leds, NUM_LEDS, CRGB::Gray);
FastLED.show();
delay(100);
break;
// Rain conditions
case 1063: case 1150: case 1153:
case 1180: case 1183: case 1240:
rainEffect(5); // Light rain
break;
case 1186: case 1189: case 1243:
rainEffect(10); // Moderate rain
break;
case 1192: case 1195: case 1246:
rainEffect(20); // Heavy rain
break;
// Snow conditions
case 1066: case 1210: case 1213: case 1255:
snowEffect(5); // Light snow
break;
case 1114: case 1219: case 1258:
snowEffect(10); // Moderate snow
break;
case 1117: case 1222: case 1225:
snowEffect(20); // Heavy snow/Blizzard
break;
// Thunder conditions
case 1273: case 1276: case 1279: case 1282:
thunderEffect();
rainEffect(10);
break;
default:
clearLEDs();
FastLED.show();
break;
}
}
void loop() {
// Example: Test all weather codes
static int testCode = 1000;
static bool isDay = true;
displayWeather(testCode, isDay);
// Uncomment to test different codes:
// if (Serial.available() > 0) {
// testCode = Serial.parseInt();
// Serial.println(testCode);
// }
}Editor is loading...
Leave a Comment