https://forum.arduino.cc/t/easiest-way-to-slowly-ramp-led-strip/1329379
# include <Wire.h>
# include <RTClib.h>
# include <FastLED.h>
# define LED_PIN 2
# define NUM_LEDS 12
# define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
RTC_DS3231 rtc;
// Time settings
int sunriseHour = 6; // Default sunrise time hour
int sunriseMinute = 0; // Default sunrise time minute
int sunsetHour = 18; // Default sunset time hour
int sunsetMinute = 0; // Default sunset time minute
unsigned long sunriseStartMillis;
unsigned long sunsetStartMillis;
bool isSunrise = false;
bool isSunset = false;
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
rtc.begin();
// Set the RTC time if needed (uncomment the next line to set)
rtc.adjust(DateTime(2024, 12, 8, 5, 59, 0));
// Set default sunrise/sunset times if needed
// rtc.adjust(DateTime(2023, 10, 1, 12, 0, 0)); // Set time for testing
}
void loop() {
DateTime now = rtc.now();
int currentHour = now.hour();
int currentMinute = now.minute();
// Check if it's time for sunrise or sunset
if (currentHour == sunriseHour && currentMinute == sunriseMinute) {
isSunrise = true;
isSunset = false;
sunriseStartMillis = millis();
} else if (currentHour == sunsetHour && currentMinute == sunsetMinute) {
isSunset = true;
isSunrise = false;
sunsetStartMillis = millis();
}
if (isSunrise) {
performSunrise();
} else if (isSunset) {
performSunset();
}
FastLED.show();
delay(1000); // Adjust delay as needed
}
void performSunrise() {
unsigned long elapsed = millis() - sunriseStartMillis;
if (elapsed < 1800000) { // 30 minutes in milliseconds
float progress = (float)elapsed / 1800000.0;
// Brightness from 0 to 255
uint8_t brightness = progress * BRIGHTNESS;
// Color transition from orange to white
CRGB color = blend(CRGB(255, 165, 0), CRGB(255, 255, 255), brightness);
fill_solid(leds, NUM_LEDS, color);
FastLED.setBrightness(brightness);
} else {
// Maintain full brightness white after sunrise
fill_solid(leds, NUM_LEDS, CRGB(255, 255, 255));
FastLED.setBrightness(BRIGHTNESS);
}
}
void performSunset() {
unsigned long elapsed = millis() - sunsetStartMillis;
if (elapsed < 1800000) { // 30 minutes in milliseconds
float progress = (float)elapsed / 1800000.0;
// Brightness from 255 to 0
uint8_t brightness = BRIGHTNESS * (1.0 - progress);
// Color transition from white to dark orange to magenta to blue
CRGB color1 = CRGB(255, 255, 255);
CRGB color2 = CRGB(255, 165, 0);
CRGB color3 = CRGB(128, 0, 128); // Magenta
CRGB color4 = CRGB(0, 0, 255); // Blue
if (progress < 0.33) {
// First third: white to dark orange
CRGB color = blend(color1, color2, progress * 3 * 100);
fill_solid(leds, NUM_LEDS, color);
} else if (progress < 0.66) {
// Second third: dark orange to magenta
CRGB color = blend(color2, color3, (progress - 1.0 / 3.0) * 3 * 100);
fill_solid(leds, NUM_LEDS, color);
} else {
// Last third: magenta to blue
CRGB color = blend(color3, color4, (progress - 2.0 / 3.0) * 3 * 100);
fill_solid(leds, NUM_LEDS, color);
}
FastLED.setBrightness(brightness);
} else {
// Turn off LEDs after sunset
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.setBrightness(0);
isSunset = false;
}
}
// Function to set the time on the RTC (call this function with new time)
void setTime(int year, int month, int day, int hour, int minute, int second) {
rtc.adjust(DateTime(year, month, day, hour, minute, second));
}
// Functions to set sunrise and sunset times
void setSunriseTime(int hour, int minute) {
sunriseHour = hour;
sunriseMinute = minute;
}
void setSunsetTime(int hour, int minute) {
sunsetHour = hour;
sunsetMinute = minute;
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
rgb1:VDD
rgb1:DOUT
rgb1:VSS
rgb1:DIN
rgb2:VDD
rgb2:DOUT
rgb2:VSS
rgb2:DIN
rgb3:VDD
rgb3:DOUT
rgb3:VSS
rgb3:DIN
rgb4:VDD
rgb4:DOUT
rgb4:VSS
rgb4:DIN
rgb5:VDD
rgb5:DOUT
rgb5:VSS
rgb5:DIN
rgb6:VDD
rgb6:DOUT
rgb6:VSS
rgb6:DIN
rgb7:VDD
rgb7:DOUT
rgb7:VSS
rgb7:DIN
rgb8:VDD
rgb8:DOUT
rgb8:VSS
rgb8:DIN
rgb9:VDD
rgb9:DOUT
rgb9:VSS
rgb9:DIN
rgb10:VDD
rgb10:DOUT
rgb10:VSS
rgb10:DIN
rgb11:VDD
rgb11:DOUT
rgb11:VSS
rgb11:DIN
rgb12:VDD
rgb12:DOUT
rgb12:VSS
rgb12:DIN
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW