end of year, silv. countdown

This commit is contained in:
cschwinne 2016-12-31 21:10:33 +01:00
parent 30cfbff5c9
commit 7cd7108aa7
5 changed files with 191 additions and 121 deletions

View File

@ -50,7 +50,6 @@ void WS2812FX::service() {
if(now - _mode_last_call_time > _mode_delay) {
CALL_MODE(_mode_index);
_counter_mode_call++;
dofade();
_mode_last_call_time = now;
}
}
@ -1303,11 +1302,9 @@ void WS2812FX::mode_fire_flicker_int(int rev_intensity)
_mode_delay = 10 + ((500 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
}
void WS2812FX::dofade(void)
void WS2812FX::mode_fade_down(void)
{
if (_fade_amt > 0)
{
for(uint16_t i=0; i < _led_count; i++) {
for(uint16_t i=0; i < _led_count; i++) {
uint32_t px_rgb = Adafruit_NeoPixel::getPixelColor(i);
byte px_r = (px_rgb & 0x00FF0000) >> 16;
@ -1315,19 +1312,15 @@ void WS2812FX::dofade(void)
byte px_b = (px_rgb & 0x000000FF) >> 0;
// fade out (divide by 2)
px_r = (double)px_r *((double)_fade_amt/256);
px_g = (double)px_g *((double)_fade_amt/256);
px_b = (double)px_b *((double)_fade_amt/256);
px_r = px_r >> 1;
px_g = px_g >> 1;
px_b = px_b >> 1;
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
Adafruit_NeoPixel::show();
}
}
void WS2812FX::setFade(int sp)
{
_fade_amt = sp;
_mode_delay = 100 + ((100 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
}
void WS2812FX::setIndividual(int i)

View File

@ -50,7 +50,7 @@
#define BRIGHTNESS_MIN 0
#define BRIGHTNESS_MAX 255
#define MODE_COUNT 47
#define MODE_COUNT 48
#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
@ -155,6 +155,7 @@ class WS2812FX : public Adafruit_NeoPixel {
_mode[FX_MODE_MERRY_CHRISTMAS] = &WS2812FX::mode_merry_christmas;
_mode[FX_MODE_FIRE_FLICKER] = &WS2812FX::mode_fire_flicker;
_mode[FX_MODE_FIRE_FLICKER_SOFT] = &WS2812FX::mode_fire_flicker_soft;
_mode[FX_MODE_FADE_DOWN] = &WS2812FX::mode_fade_down;
_name[FX_MODE_STATIC] = "Static";
_name[FX_MODE_BLINK] = "Blink";
@ -203,6 +204,7 @@ class WS2812FX : public Adafruit_NeoPixel {
_name[FX_MODE_MERRY_CHRISTMAS] = "Merry Christmas";
_name[FX_MODE_FIRE_FLICKER] = "Fire Flicker";
_name[FX_MODE_FIRE_FLICKER_SOFT] = "Fire Flicker (soft)";
_name[FX_MODE_FADE_DOWN] = "Fade (Internal)";
_mode_index = DEFAULT_MODE;
_speed = DEFAULT_SPEED;
@ -216,7 +218,6 @@ class WS2812FX : public Adafruit_NeoPixel {
_counter_mode_call = 0;
_counter_mode_step = 0;
_locked = new boolean[n];
_fade_amt = 0;
}
void
@ -314,7 +315,8 @@ class WS2812FX : public Adafruit_NeoPixel {
mode_merry_christmas(void),
mode_fire_flicker(void),
mode_fire_flicker_soft(void),
mode_fire_flicker_int(int);
mode_fire_flicker_int(int),
mode_fade_down(void);
boolean
_running;
@ -337,8 +339,7 @@ class WS2812FX : public Adafruit_NeoPixel {
_counter_mode_call,
_counter_mode_step,
_mode_color,
_mode_delay,
_fade_amt;
_mode_delay;
unsigned long
_mode_last_call_time;

View File

@ -22,7 +22,7 @@
* @author Christian Schwinne
*/
//Hardware-settings (only changeble via code)
uint8_t led_amount = 9;
uint8_t led_amount = 10;
uint8_t buttonPin = 0; //needs pull-up
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //Central European Summer Time
@ -64,20 +64,17 @@ uint8_t effectDefault = 0;
uint8_t effectSpeedDefault = 75;
boolean ntpEnabled = true;
const char* ntpServerName = "time.nist.gov";
long ntpRetryMs = 20000;
long ntpRetryMs = 12000;
long ntpResyncMs = 72000000;
int overlayMin = 0, overlayMax = 9;
int analogClock12pixel = 25;
boolean analogClockSecondsTrail = false;
boolean analogClock5MinuteMarks = true;
boolean overlayBackgroundBlack = true;
boolean nixieClockDisplaySeconds = true;
boolean nixieClock12HourFormat = false;
boolean overlayReverse = true;
uint8_t overlaySpeed = 200;
uint32_t overlayColor = 0x0000FF00;
double transitionResolution = 0.011;
//Internal vars
@ -110,11 +107,15 @@ boolean ntpConnected = false;
boolean ntpSyncNeeded = true;
boolean ntpPacketSent = false;
long ntpPacketSentTime, ntpSyncTime;
uint8_t overlayCurrent = 0;
uint8_t overlayCurrent = 5;
long overlayRefreshMs = 200;
long overlayRefreshedTime;
int overlayArr[6];
int nixieClockI = 0;
int overlayDur[6];
int overlayPauseDur[6];
int nixieClockI = -1;
boolean nixiePause;
long countdownTime = 1483225200L;
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;

View File

@ -237,6 +237,11 @@ boolean handleSet(String req)
effectUpdated = true;
}
}
pos = req.indexOf("OL=");
if (pos > 0) {
overlayCurrent = req.substring(pos + 3).toInt();
strip.unlockAll();
}
pos = req.indexOf("I=");
if (pos > 0){
int index = req.substring(pos + 2).toInt();

View File

@ -1,3 +1,105 @@
void nixieDisplay(int num[], int dur[], int pausedur[], int cnt)
{
strip.setRange(overlayMin, overlayMax, 0);
if (num[nixieClockI] >= 0 && !nixiePause)
{
strip.setIndividual(num[nixieClockI], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(num[nixieClockI]);
}
if (!nixiePause)
{
overlayRefreshMs = dur[nixieClockI];
} else
{
overlayRefreshMs = pausedur[nixieClockI];
}
if (pausedur[nixieClockI] > 0 && !nixiePause)
{
nixiePause = true;
} else {
if (nixieClockI < cnt -1)
{
nixieClockI++;
} else
{
nixieClockI = -1;
}
nixiePause = false;
}
}
void nixieNumber(int number, int dur)
{
if (nixieClockI < 0)
{
Serial.print(number);
int digitCnt = -1;
int digits[4];
digits[3] = number/1000;
digits[2] = (number/100)%10;
digits[1] = (number/10)%10;
digits[0] = number%10;
if (number > 999) //four digits
{
digitCnt = 4;
} else if (number > 99) //three digits
{
digitCnt = 3;
} else if (number > 9) //two digits
{
digitCnt = 2;
} else { //single digit
digitCnt = 1;
}
Serial.print(" ");
for (int i = 0; i < digitCnt; i++)
{
Serial.print(digits[i]);
overlayArr[digitCnt-1-i] = digits[i];
overlayDur[digitCnt-1-i] = ((dur/4)*3)/digitCnt;
overlayPauseDur[digitCnt-1-i] = 0;
}
Serial.println(" ");
for (int i = 1; i < digitCnt; i++)
{
if (overlayArr[i] == overlayArr[i-1])
{
overlayPauseDur[i-1] = dur/12;
overlayDur[i-1] = overlayDur[i-1]-dur/12;
}
}
for (int i = digitCnt; i < 6; i++)
{
overlayArr[i] = -1;
overlayDur[i] = 0;
overlayPauseDur[i] = 0;
}
overlayPauseDur[5] = dur/4;
for (int i = 0; i < 6; i++)
{
if (overlayArr[i] != -1)
{
overlayArr[i] = overlayArr[i] + overlayMin;
if (overlayReverse)
overlayArr[i] = overlayMax - overlayArr[i];
}
}
for (int i = 0; i <6; i++)
{
Serial.print(overlayArr[i]);
Serial.print(" ");
Serial.print(overlayDur[i]);
Serial.print(" ");
Serial.print(overlayPauseDur[i]);
Serial.print(" ");
}
Serial.println(" ");
nixieClockI = 0;
} else {
nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
}
}
void handleOverlays()
{
//properties: range, (color)
@ -49,10 +151,8 @@ void handleOverlays()
overlayRefreshMs = 998; break;
}
case 3: {
switch (nixieClockI)
if (nixieClockI < 0)
{
case 0:
strip.setFade(99);
local = TZ.toLocal(now(), &tcr);
overlayArr[0] = hour(local);
if (nixieClock12HourFormat && overlayArr[0] > 12)
@ -84,119 +184,89 @@ void handleOverlays()
if (overlayReverse)
overlayArr[i] = overlayMax - overlayArr[i];
}
Serial.print(overlayArr[i]);
Serial.print(" ");
}
Serial.println(" ");
if (overlayBackgroundBlack) {
strip.setRange(overlayMin, overlayMax, 0);
strip.setIndividual(overlayArr[0], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(overlayArr[0]);
overlayDur[0] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[1] == overlayArr[0])
{
overlayPauseDur[0] = 3 + 3*(255 - overlaySpeed);
} else
{
strip.unlockAll();
strip.setIndividual(overlayArr[0], overlayColor);
}
overlayRefreshMs = 10 + 10*(255 - overlaySpeed);
nixieClockI++;
break;
case 1:
if (overlayBackgroundBlack) {
if (overlayArr[1] != -1)
{
strip.setRange(overlayMin, overlayMax, 0);
strip.setIndividual(overlayArr[1], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(overlayArr[1]);
}
} else
{
if (overlayArr[1] != -1)
{
strip.unlockAll();
strip.setIndividual(overlayArr[1], overlayColor);
}
overlayPauseDur[0] = 0;
}
if (overlayArr[1] == -1)
{
overlayRefreshMs = 10 + 10*(255 - overlaySpeed);
overlayDur[1] = 0;
} else
{
overlayRefreshMs = 20 + 20*(255 - overlaySpeed);
overlayDur[1] = 12 + 12*(255 - overlaySpeed);
}
nixieClockI++;
break;
case 2:
if (overlayBackgroundBlack) {
strip.setRange(overlayMin, overlayMax, 0);
strip.setIndividual(overlayArr[2], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(overlayArr[2]);
overlayPauseDur[1] = 9 + 9*(255 - overlaySpeed);
overlayDur[2] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[2] == overlayArr[3])
{
overlayPauseDur[2] = 3 + 3*(255 - overlaySpeed);
} else
{
strip.unlockAll();
strip.setIndividual(overlayArr[2], overlayColor);
}
overlayRefreshMs = 10 + 10*(255 - overlaySpeed);
nixieClockI++;
break;
case 3:
if (overlayBackgroundBlack) {
strip.setRange(overlayMin, overlayMax, 0);
strip.setIndividual(overlayArr[3], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(overlayArr[3]);
} else
{
strip.unlockAll();
strip.setIndividual(overlayArr[3], overlayColor);
}
overlayRefreshMs = 20 + 20*(255 - overlaySpeed);
nixieClockI++;
break;
case 4:
if (overlayBackgroundBlack) {
if (overlayArr[4] != -1)
{
strip.setRange(overlayMin, overlayMax, 0);
strip.setIndividual(overlayArr[4], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(overlayArr[4]);
}
} else
{
if (overlayArr[4] != -1)
{
strip.unlockAll();
strip.setIndividual(overlayArr[4], overlayColor);
}
{
overlayPauseDur[2] = 0;
}
overlayDur[3] = 12 + 12*(255 - overlaySpeed);
overlayPauseDur[3] = 9 + 9*(255 - overlaySpeed);
if (overlayArr[4] == -1)
{
overlayRefreshMs = 0;
overlayDur[4] = 0;
overlayPauseDur[4] = 0;
overlayDur[5] = 0;
} else
{
overlayRefreshMs = 10 + 10*(255 - overlaySpeed);
}
nixieClockI++;
break;
case 5:
if (overlayBackgroundBlack) {
if (overlayArr[5] != -1)
overlayDur[4] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[5] == overlayArr[4])
{
strip.setRange(overlayMin, overlayMax, 0);
strip.setIndividual(overlayArr[5], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(overlayArr[5]);
}
} else
{
if (overlayArr[5] != -1)
overlayPauseDur[4] = 3 + 3*(255 - overlaySpeed);
} else
{
strip.unlockAll();
strip.setIndividual(overlayArr[5], overlayColor);
overlayPauseDur[4] = 0;
}
overlayDur[5] = 12 + 12*(255 - overlaySpeed);
}
overlayRefreshMs = 30 + 30*(255 - overlaySpeed);
nixieClockI = 0;
break;
}
overlayPauseDur[5] = 22 + 22*(255 - overlaySpeed);
nixieClockI = 0;
} else
{
nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
}
}
case 5: {//countdown
if (now() >= countdownTime)
{
if (effectCurrent != 8){
effectCurrent = 8;
strip.setMode(8);
strip.setSpeed(255);
}
nixieNumber(2017, 2017);
} else
{
long diff = countdownTime - now();
if (diff > 86313600L) //display in years if more than 999 days
{
diff = diff/31557600L;
} else if (diff > 3596400) //display in days if more than 999 hours
{
diff = diff/86400;
} else if (diff > 59940) //display in hours if more than 999 minutes
{
diff = diff/1440;
} else if (diff > 999) //display in minutes if more than 999 seconds
{
diff = diff/60;
}
nixieNumber(diff, 800);
}
}
}
}
}