//XMAS SHIELD an esp32 shield for christmass crib nativity effects //https://xmas-shield.jimdofree.com/ // version 0.1 // h hmi variable, v internal variable, c constant #include #include "FastLED.h" #define NUM_LEDS 150 #define DATA_PIN 14 #define BRIGHTNESS 255 CRGB rawleds[NUM_LEDS]; CRGBSet leds(rawleds, NUM_LEDS); CRGBSet leds1(leds(0,49)); CRGBSet leds2(leds(50,99)); CRGBSet leds3(leds(100,149)); int hSunriseDuration = 15000; // sunrise duration in ms int hDayDurantion = 15000; // day duration in ms int hSunsetDurantion = 15000; // sunset duration in ms int hNightDurantion = 15000; // sunset duration in ms int vPhaseDay =0; // 0 Day, 1 Sunset, 2 Night, 3 Sunrise int vSunset = hDayDurantion; int vNight = hDayDurantion + hSunriseDuration; int vSunrise = vNight + hNightDurantion; int vDay = vSunrise + hSunriseDuration; int vMem = 0; int paletteIndex = 0; float interval; unsigned long previousMillis = 0; unsigned long currentMillis =0; unsigned long previousSunset =0; CRGBPalette16 cPalSunset; CRGBPalette16 cPalSunrise; CRGBPalette16 cPalSunrise2; CRGBPalette16 cPalSunset2; void setup() { delay(2000); FastLED.addLeds(leds, NUM_LEDS); FastLED.setCorrection(TypicalSMD5050); FastLED.setTemperature(Tungsten40W ); Serial.begin(9600); SetupPalSunset(); SetupPalSunrise(); } void loop() { // here is where you'd put code that needs to be running all the time. // check to see if it's time to blink the LED; that is, if the // difference between the current time and last time you blinked // the LED is bigger than the interval at which you want to // blink the LED. currentMillis = millis(); vSunset = hDayDurantion; vNight = hDayDurantion + hSunriseDuration; vSunrise = vNight + hNightDurantion; vDay = vSunrise + hSunriseDuration; //Serial.println(vSunset); //Serial.println(vNight); if ((currentMillis - previousMillis)>= vSunset && (currentMillis - previousMillis) < vNight) { vPhaseDay =1; // is Sunset } if ((currentMillis - previousMillis)>= vNight && (currentMillis - previousMillis) < vSunrise) { vPhaseDay =2; // is Night } if ((currentMillis - previousMillis)>= vSunrise && (currentMillis - previousMillis) < vDay) { vPhaseDay =3; // is Sunrise } if ((currentMillis - previousMillis)>= vDay) { vPhaseDay =0; // is Sunrise previousMillis = currentMillis; } if (vPhaseDay == 0){ if (vMem == 0){ Serial.println("is day"); vMem =1; fill_solid(leds, 150,CRGB::White ); FastLED.show(); } } if (vPhaseDay == 1){ if (vMem == 1){ Serial.println("is Sunset"); vMem =2; previousSunset=currentMillis; paletteIndex = 0; interval = long(hSunsetDurantion / 255); CRGB colour = ColorFromPalette(cPalSunset2, paletteIndex, 255, LINEARBLEND); fill_solid(leds, 150, colour ); FastLED.show(); } if((currentMillis-previousSunset)>= interval){ previousSunset=currentMillis; if (paletteIndex < 240) paletteIndex++; CRGB colour = ColorFromPalette(cPalSunset2, paletteIndex, 255, LINEARBLEND); //Serial.println(paletteIndex); fill_solid(leds, 150, colour ); FastLED.show(); } } if (vPhaseDay == 2){ if (vMem == 2){ Serial.println("is night"); vMem =3; fill_solid(leds, 150, CRGB(0, 2, 7) ); FastLED.show(); } } if (vPhaseDay == 3){ if (vMem == 3){ Serial.println("is Sunrise"); vMem =0; previousSunset=currentMillis; paletteIndex = 0; interval = long(hSunsetDurantion / 255); CRGB colour = ColorFromPalette(cPalSunrise2, paletteIndex, 255, LINEARBLEND); fill_solid(leds, 150, colour ); FastLED.show(); } if((currentMillis-previousSunset)>= interval){ previousSunset=currentMillis; if (paletteIndex < 240) paletteIndex++; CRGB colour = ColorFromPalette(cPalSunrise2, paletteIndex, 255, LINEARBLEND); //Serial.println(paletteIndex); fill_solid(leds, 150, colour ); FastLED.show(); } } } void SetupPalSunset() { CRGB yellow = CRGB(255, 229, 119); CRGB orange = CRGB(254, 192, 81); CRGB salmon = CRGB(255, 137, 103); CRGB dsalmon = CRGB(253, 96, 81); CRGB dark = CRGB(57, 32, 51); CRGB red = CRGB(130, 33, 14); CRGB darkblue = CRGB(6, 4, 5); CRGB white = CRGB::White; CRGB night=CRGB(0,2,7); cPalSunset2 = CRGBPalette16(white,red,night); cPalSunset = CRGBPalette16( white, yellow, yellow, yellow, orange, orange, orange, orange, salmon, salmon, salmon, dsalmon, dsalmon, dsalmon, dsalmon, darkblue ); } void SetupPalSunrise() { CRGB yellow = CRGB(255, 229, 119); CRGB orange = CRGB(254, 192, 81); CRGB salmon = CRGB(255, 137, 103); CRGB dsalmon = CRGB(253, 96, 81); CRGB dark = CRGB(57, 32, 51); CRGB white = CRGB::White; CRGB red = CRGB(130, 33, 14); CRGB darkblue = CRGB(6, 4, 5); CRGB night=CRGB(0,2,7); cPalSunrise2 = CRGBPalette16(night,red,white); cPalSunrise = CRGBPalette16( darkblue, dsalmon, dsalmon, dsalmon, salmon, salmon, salmon, salmon, orange, orange, orange, yellow, yellow, yellow, yellow, white ); }