#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 24
#define BRIGHTNESS 32
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 100
CRGB rawleds[NUM_LEDS];
CRGBSet leds(rawleds, NUM_LEDS);
CRGBSet ring1(leds(0,7));
CRGBSet ring2(leds(8,15));
CRGBSet ring3(leds(16,23));
CRGBSet all(leds(0,23));
struct CRGB * ledsarray[] ={ring1, ring2, ring3};
unsigned long previousMillis = 0;
const long interval = 2500;
// Define some usable/nice colors:
CRGB Mask = CRGB (0, 100, 255); //Mask
CRGB DarkBramble = CRGB (130, 180, 255); //Dark Bramble
CRGB GiantDeep = CRGB (0, 170, 135); //Giant's Deep
CRGB BrittleHollow = CRGB (60, 115, 175); //Brittle Hollow
CRGB HollowLantern = CRGB (255, 80, 0); //Hollow's Lantern
CRGB TimberHearth = CRGB (50, 105, 75); //Timber Hearth
CRGB HourglassTwin = CRGB (170, 110, 0); //Hourglass Twin
CRGB Interloper = CRGB (0, 200, 255); //Interloper
CRGB QuantumMoon = CRGB (145, 50, 250); //Quantum Moon
CRGB sunColor0 = CRGB(255,200,0); // Sun starting color
CRGB sunColor1 = CRGB(255,0,0); // Sun target color
CRGB sunColor2 = CRGB(200,235,255); //Sun going white
CRGB EoU0 = CRGB(200,235,255); //Sun going white
CRGB EoU1 = CRGB(25, 0, 70); //Eye of the universe
CRGB Black = CRGB::Black;
int nextplanet = 0;
//Sun turning RED
const uint8_t fadeRate = 50; // new step
const uint8_t fadeRate1 = 5; // new step
boolean fadeToColor = 1; // turns on/off the fading toward target
boolean fadeToColor1 = 1; // turns on/off the fading toward target
boolean ring = 1; // turns on/off the fading toward target
void setup() {
// delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
void loop() {
unsigned long currentMillis = millis();
// Turn sun on
//Sun fading
EVERY_N_MILLISECONDS(fadeRate) {
if (fadeToColor) {
nblendU8TowardU8( sunColor0.r, sunColor1.r);
nblendU8TowardU8( sunColor0.g, sunColor1.g);
nblendU8TowardU8( sunColor0.b, sunColor1.b);
sunColor0 = CRGB(sunColor0.r,sunColor0.g,sunColor0.b);
leds[9] = sunColor0;
}
if (sunColor0 == sunColor1) {
sunColor1 = sunColor2;
if (sunColor0 == sunColor2) {
fadeToColor = 0; // stop fading
}
}
FastLED.show();
}
//Planets
if (nextplanet < 8) {
if( currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (nextplanet == 0) {
leds[1] = DarkBramble;
leds[0] = Black;}
if (nextplanet == 1) {
leds[2] = GiantDeep;}
if (nextplanet == 2) {
leds[3] = BrittleHollow;
leds[4] = HollowLantern; }
if (nextplanet == 3) {
leds[5] = TimberHearth;}
if (nextplanet == 4) {
leds[6] = HourglassTwin;}
if (nextplanet == 5) {
leds[7] = Interloper;}
if (nextplanet == 6) {
leds[8] = QuantumMoon;}
FastLED.show();
nextplanet = nextplanet + 1;
}
}
if (nextplanet == 8) {
if (ring) {delay(2000);
ring1 = sunColor2;
FastLED.show();
delay(50);
ring1 = Black;
ring2 = sunColor2;
FastLED.show();
delay(50);
ring2 = Black;
ring3 = sunColor2;
FastLED.show();
delay(50);
ring3 = sunColor2;
FastLED.show();
delay(50);
all = Black;
FastLED.show();
ring = 0;
fadeToColor = 0;
} // start background fading
EVERY_N_MILLISECONDS(fadeRate1) {
if (fadeToColor1) {
nblendU8TowardU8( EoU0.r, EoU1.r);
nblendU8TowardU8( EoU0.g, EoU1.g);
nblendU8TowardU8( EoU0.b, EoU1.b);
EoU0 = CRGB(EoU0.r,EoU0.g,EoU0.b);
all = EoU0;
if (EoU0 == EoU1) {
delay(3000);
EoU1 = Black;
if (EoU0 == Black) {
leds[0] = Mask;
FastLED.show();
delay(10000);
nextplanet = 0;
fadeToColor1 = 0; // stop fading
}
}
FastLED.show();
}
}
}
}
//Sun gradient steps
void nblendU8TowardU8(uint8_t& current, const uint8_t target)
{
if( current == target) {
return;
}
if( current < target ) {
uint8_t delta = target - current;
delta = scale8_video( delta, 1);
current += delta;
} else {
uint8_t delta = current - target;
delta = scale8_video( delta, 1);
current -= delta;
}
}