In digital clock dev

This commit is contained in:
cschwinne 2016-12-31 17:36:07 +01:00
parent 31e3daf3e3
commit 30cfbff5c9
5 changed files with 209 additions and 9 deletions

View File

@ -50,6 +50,7 @@ void WS2812FX::service() {
if(now - _mode_last_call_time > _mode_delay) { if(now - _mode_last_call_time > _mode_delay) {
CALL_MODE(_mode_index); CALL_MODE(_mode_index);
_counter_mode_call++; _counter_mode_call++;
dofade();
_mode_last_call_time = now; _mode_last_call_time = now;
} }
} }
@ -1302,6 +1303,33 @@ void WS2812FX::mode_fire_flicker_int(int rev_intensity)
_mode_delay = 10 + ((500 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX); _mode_delay = 10 + ((500 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
} }
void WS2812FX::dofade(void)
{
if (_fade_amt > 0)
{
for(uint16_t i=0; i < _led_count; i++) {
uint32_t px_rgb = Adafruit_NeoPixel::getPixelColor(i);
byte px_r = (px_rgb & 0x00FF0000) >> 16;
byte px_g = (px_rgb & 0x0000FF00) >> 8;
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);
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
Adafruit_NeoPixel::show();
}
}
void WS2812FX::setFade(int sp)
{
_fade_amt = sp;
}
void WS2812FX::setIndividual(int i) void WS2812FX::setIndividual(int i)
{ {
if (i >= 0 && i < _led_count) if (i >= 0 && i < _led_count)

View File

@ -99,6 +99,7 @@
#define FX_MODE_MERRY_CHRISTMAS 44 #define FX_MODE_MERRY_CHRISTMAS 44
#define FX_MODE_FIRE_FLICKER 45 #define FX_MODE_FIRE_FLICKER 45
#define FX_MODE_FIRE_FLICKER_SOFT 46 #define FX_MODE_FIRE_FLICKER_SOFT 46
#define FX_MODE_FADE_DOWN 47
class WS2812FX : public Adafruit_NeoPixel { class WS2812FX : public Adafruit_NeoPixel {
@ -215,6 +216,7 @@ class WS2812FX : public Adafruit_NeoPixel {
_counter_mode_call = 0; _counter_mode_call = 0;
_counter_mode_step = 0; _counter_mode_step = 0;
_locked = new boolean[n]; _locked = new boolean[n];
_fade_amt = 0;
} }
void void
@ -240,7 +242,8 @@ class WS2812FX : public Adafruit_NeoPixel {
lockAll(void), lockAll(void),
unlock(int i), unlock(int i),
unlockRange(int i, int i2), unlockRange(int i, int i2),
unlockAll(void); unlockAll(void),
setFade(int sp);
boolean boolean
isRunning(void), isRunning(void),
@ -261,6 +264,7 @@ class WS2812FX : public Adafruit_NeoPixel {
private: private:
void void
dofade(void),
strip_off(void), strip_off(void),
strip_off_respectLock(void), strip_off_respectLock(void),
mode_static(void), mode_static(void),
@ -310,8 +314,7 @@ class WS2812FX : public Adafruit_NeoPixel {
mode_merry_christmas(void), mode_merry_christmas(void),
mode_fire_flicker(void), mode_fire_flicker(void),
mode_fire_flicker_soft(void), mode_fire_flicker_soft(void),
mode_fire_flicker_int(int), mode_fire_flicker_int(int);
mode_individual_control(void);
boolean boolean
_running; _running;
@ -334,7 +337,8 @@ class WS2812FX : public Adafruit_NeoPixel {
_counter_mode_call, _counter_mode_call,
_counter_mode_step, _counter_mode_step,
_mode_color, _mode_color,
_mode_delay; _mode_delay,
_fade_amt;
unsigned long unsigned long
_mode_last_call_time; _mode_last_call_time;

View File

@ -22,7 +22,7 @@
* @author Christian Schwinne * @author Christian Schwinne
*/ */
//Hardware-settings (only changeble via code) //Hardware-settings (only changeble via code)
uint8_t led_amount = 84; uint8_t led_amount = 9;
uint8_t buttonPin = 0; //needs pull-up uint8_t buttonPin = 0; //needs pull-up
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //Central European Summer Time TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //Central European Summer Time
@ -66,10 +66,17 @@ boolean ntpEnabled = true;
const char* ntpServerName = "time.nist.gov"; const char* ntpServerName = "time.nist.gov";
long ntpRetryMs = 20000; long ntpRetryMs = 20000;
long ntpResyncMs = 72000000; long ntpResyncMs = 72000000;
int overlayMin = 0, overlayMax = 79; int overlayMin = 0, overlayMax = 9;
int analogClock12pixel = 25; int analogClock12pixel = 25;
boolean analogClockSecondsTrail = false; boolean analogClockSecondsTrail = false;
boolean analogClock5MinuteMarks = true; 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; double transitionResolution = 0.011;
@ -97,14 +104,17 @@ uint8_t effectSpeed = 75;
boolean udpConnected = false; boolean udpConnected = false;
byte udpIn[16]; byte udpIn[16];
IPAddress ntpIp; IPAddress ntpIp;
IPAddress ntpBackupIp(134,130,5,17);
byte ntpBuffer[48]; byte ntpBuffer[48];
boolean ntpConnected = false; boolean ntpConnected = false;
boolean ntpSyncNeeded = true; boolean ntpSyncNeeded = true;
boolean ntpPacketSent = false; boolean ntpPacketSent = false;
long ntpPacketSentTime, ntpSyncTime; long ntpPacketSentTime, ntpSyncTime;
uint8_t overlayCurrent = 2; uint8_t overlayCurrent = 0;
long overlayRefreshMs = 200; long overlayRefreshMs = 200;
long overlayRefreshedTime; long overlayRefreshedTime;
int overlayArr[6];
int nixieClockI = 0;
ESP8266WebServer server(80); ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater; ESP8266HTTPUpdateServer httpUpdater;

View File

@ -27,6 +27,11 @@ void handleNetworkTime()
} else } else
{ {
WiFi.hostByName(ntpServerName, ntpIp); WiFi.hostByName(ntpServerName, ntpIp);
if (ntpIp[0] == 0)
{
Serial.println("DNS f!");
ntpIp = ntpBackupIp;
}
sendNTPpacket(); sendNTPpacket();
ntpPacketSent = true; ntpPacketSent = true;
ntpPacketSentTime = millis(); ntpPacketSentTime = millis();

View File

@ -5,12 +5,15 @@ void handleOverlays()
//1 solid color //1 solid color
//2 analog clock //2 analog clock
//3 digital nixie-style clock one digit //3 digital nixie-style clock one digit
//4 just static hour
//5 analog countdown
//6 digital one digit countdown
if (millis() - overlayRefreshedTime > overlayRefreshMs) if (millis() - overlayRefreshedTime > overlayRefreshMs)
{ {
overlayRefreshedTime = millis(); overlayRefreshedTime = millis();
switch (overlayCurrent) switch (overlayCurrent)
{ {
case 2: //2 analog clock case 2: {//2 analog clock
int overlaySize = overlayMax - overlayMin +1; int overlaySize = overlayMax - overlayMin +1;
strip.unlockAll(); strip.unlockAll();
local = TZ.toLocal(now(), &tcr); local = TZ.toLocal(now(), &tcr);
@ -43,7 +46,157 @@ void handleOverlays()
} }
strip.setIndividual(minutePixel, 0x00FF00); strip.setIndividual(minutePixel, 0x00FF00);
strip.setIndividual(hourPixel, 0xFF0000); strip.setIndividual(hourPixel, 0xFF0000);
overlayRefreshMs = 998; overlayRefreshMs = 998; break;
}
case 3: {
switch (nixieClockI)
{
case 0:
strip.setFade(99);
local = TZ.toLocal(now(), &tcr);
overlayArr[0] = hour(local);
if (nixieClock12HourFormat && overlayArr[0] > 12)
{
overlayArr[0] = overlayArr[0]%12;
}
overlayArr[1] = -1;
if (overlayArr[0] > 9)
{
overlayArr[1] = overlayArr[0]%10;
overlayArr[0] = overlayArr[0]/10;
}
overlayArr[2] = minute(local);
overlayArr[3] = overlayArr[2]%10;
overlayArr[2] = overlayArr[2]/10;
overlayArr[4] = -1;
overlayArr[5] = -1;
if (nixieClockDisplaySeconds)
{
overlayArr[4] = second(local);
overlayArr[5] = overlayArr[4]%10;
overlayArr[4] = overlayArr[4]/10;
}
for (int i = 0; i < 6; i++)
{
if (overlayArr[i] != -1)
{
overlayArr[i] = overlayArr[i] + overlayMin;
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]);
} 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);
}
}
if (overlayArr[1] == -1)
{
overlayRefreshMs = 10 + 10*(255 - overlaySpeed);
} else
{
overlayRefreshMs = 20 + 20*(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]);
} 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);
}
}
if (overlayArr[4] == -1)
{
overlayRefreshMs = 0;
} else
{
overlayRefreshMs = 10 + 10*(255 - overlaySpeed);
}
nixieClockI++;
break;
case 5:
if (overlayBackgroundBlack) {
if (overlayArr[5] != -1)
{
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)
{
strip.unlockAll();
strip.setIndividual(overlayArr[5], overlayColor);
}
}
overlayRefreshMs = 30 + 30*(255 - overlaySpeed);
nixieClockI = 0;
break;
}
}
} }
} }
} }