#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 30 // Adjust based on your LED strip length
#define SYNC_PIN 2 // Communication pin to second Arduino
// Define the LED strip
CRGB leds[NUM_LEDS];
// Timing constants (in milliseconds)
const unsigned long FADE_TIME = 6000; // 10 minutes
const unsigned long HOLD_TIME = 3000; // 5 minutes
const unsigned long HOLD_TIME_GREEN = 3000; // 10 minutes
// State variables
unsigned long previousMillis = 0;
int fadeState = 0; // 0: green->blue fade, 1: blue hold, 2: blue->green fade, 3: green hold
float fadeProgress = 0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
pinMode(SYNC_PIN, OUTPUT);
FastLED.setBrightness(255);
}
void loop() {
unsigned long currentMillis = millis();
switch(fadeState) {
case 0: // Green to Blue fade
if (currentMillis - previousMillis >= (FADE_TIME / 100)) {
previousMillis = currentMillis;
fadeProgress += 1;
if (fadeProgress <= 100) {
// Interpolate between aqua green and deep blue
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(
0, // Red
255 - (fadeProgress * 2.55), // Green fade out
fadeProgress * 2.55 // Blue fade in
);
}
FastLED.show();
// Signal second Arduino about progress
digitalWrite(SYNC_PIN, HIGH);
delay(10);
digitalWrite(SYNC_PIN, LOW);
} else {
fadeState = 1; // Move to hold state
fadeProgress = 0;
previousMillis = currentMillis;
}
}
break;
case 1: // Hold blue
if (currentMillis - previousMillis >= HOLD_TIME) {
fadeState = 2;
previousMillis = currentMillis;
}
break;
case 2: // Blue to Green fade
if (currentMillis - previousMillis >= (FADE_TIME / 100)) {
previousMillis = currentMillis;
fadeProgress += 1;
if (fadeProgress <= 100) {
// Interpolate between deep blue and aqua green
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(
0, // Red
fadeProgress * 2.55, // Green fade in
255 - (fadeProgress * 2.55) // Blue fade out
);
}
FastLED.show();
// Signal second Arduino about progress
digitalWrite(SYNC_PIN, HIGH);
delay(10);
digitalWrite(SYNC_PIN, LOW);
} else {
fadeState = 3; // Move to hold state
fadeProgress = 0;
previousMillis = currentMillis;
}
}
break;
case 3: // Hold green
if (currentMillis - previousMillis >= HOLD_TIME_GREEN) {
fadeState = 0;
fadeProgress = 0;
previousMillis = currentMillis;
}
break;
}
}