#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 529 // 23 rows x 23 columns
CRGB leds[NUM_LEDS];
CRGB blueColor = CRGB(0, 0, 255); // Blue color (R,G,B)
CRGB yellowColor = CRGB(255, 255, 0); // Yellow color (R,G,B)
float time = 0.0; // Keep track of time for animation
float speed = 0.01; // Speed of wave animation
float scale = 5.0; // Scale of wave animation
float amplitude = 20.0; // Amplitude of wave animation
float period = 60.0; // Period of wave animation
unsigned long previousMillis = 0; // Keep track of the previous animation update time
unsigned long interval = 50;
float brightnessScale = 30.0; // Scale of brightness variation
float brightnessOffset = 100.0; // Offset of brightness variation
void setup() {
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
}
void loop() {
// Set every LED in the grid to blue or yellow based on row number
for (int row = 0; row < 23; row++) {
CRGB color = (row < 11) ? blueColor : yellowColor;
for (int col = 0; col < 23; col++) {
int index = row * 23 + col;
leds[index] = color;
}
}
// Add wind wave flag effect with brightness variation
for (int y = 0; y < 23; y++) {
float offset = sin((time - y * period) / period * 2 * PI) * amplitude;
for (int x = 0; x < 23; x++) {
int index = y * 23 + x;
leds[index] = blend(leds[index], CRGB::Black, 64); // Add a slight fade to the color
float brightness = (inoise8(x / brightnessScale, (time - y * period) / period, 0.0) + 1.0) * 0.5 * 255.0 + brightnessOffset; // Add the brightness variation using Perlin noise
leds[index].nscale8_video(brightness); // Scale the brightness of the color
leds[index] = leds[index] + CRGB(offset, offset, 0); // Add the wave effect
}
}
FastLED.show();
// Update time for animation based on elapsed time since the previous update
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
time += speed;
}
}