Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip all dots to blank once per hour to blank stale dots #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions countdown/config_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,37 @@
const char* ssid = "YOUR SSID";
const char* password = "YOUR WIFI PASSWORD";

struct Event {
long timeBegin;
long timeEnd;
String text1;
String text2;
String text3;
};

// Timestamps ermitteln bspw. mit Python:
// from datetime import datetime
// datetime(2024, 12, 24, 0, 0, 0, 0).timestamp()

#define EVENTDATA { \
{ \
1703444400, 1703703600, \
" bis Weihnachten ", \
" Wir wuenschen ", \
" Frohe Weihnachten "\
}, \
{ \
1704063600, 1704322800, \
" bis Neujahr ", \
" Wir wuenschen ", \
"ein gutes Neues Jahr!" \
}, \
{ \
1800000000, 1800003600, \
" bis Dings! ", \
" Wir wuenschen ", \
"ein gutes Neues Jahr!" \
} \
}

Event events[3] = EVENTDATA;
116 changes: 53 additions & 63 deletions countdown/countdown.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "font8x8_basic.h"
#include "6x8_horizontal_LSB_1.h"
#include "config.h"
//#include <WiFiClientSecure.h>
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>



// pin assignments
//
// pin on lolin32 header // pin on column driver input header
Expand Down Expand Up @@ -46,11 +49,6 @@ const byte MODE_CURTAIN_OUT = 3;
const int PAUSE_BETWEEN_DOT_FLIPS_IN_MS = 2; // lowest value to reliably flip all dots with 5A power supply (lights off)
const int MAX_PAUSE_BETWEEN_ACTIONS = 5000;

// Event time
long timeJubilee = 1700000000;
// Heilig Abend 20:00 CET
long timeJubilee2 = 1703444400;

// internal storage for the current state of the display
boolean dotmatrix[DISPLAY_WIDTH][MODULE_HEIGHT];

Expand All @@ -60,7 +58,8 @@ long lastUpdate = 0;
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);


int currentEvent;

void setup() {

Expand Down Expand Up @@ -128,82 +127,73 @@ void setup() {
flipDotSimple(x, y, false, true);
}
}

// section77 Schriftzug anzeigen
showName(true);
delay(45000);

// section77 Schriftzug wieder löschen
showName(false);

currentEvent = 0;

}


void loop() {

char txtCurTime[19];
char txtTime2Wait[19];
// char txtCurTimeOld[18];
// char txtTime2WaitOld[18];

// Display löschen
flipDisplay(false, MODE_CURTAIN_OUT);
char txtCurTime[21];
char txtTime2Wait[21];
long curTime;

if (timeClient.getEpochTime() - lastUpdate > 3600) {
timeClient.update();
lastUpdate = timeClient.getEpochTime();
// Display löschen
for (int x = 0; x < DISPLAY_WIDTH; x++) {
for (int y = 0; y < MODULE_HEIGHT; y++) {
flipDotSimple(x, y, false, true);
}
}
} else {
flipDisplay(false, MODE_CURTAIN_OUT);
}

// section77 Schriftzug anzeigen
showName(true);
delay(2000);

// section77 Schriftzug wieder löschen
showName(false);

// Countdown bis zu DEM EREIGNIS anzeigen
long curTime = timeClient.getEpochTime();
long timeToWait = timeJubilee - curTime;
sprintf(txtTime2Wait, "Noch %12ss", printfcomma(timeToWait));
if (timeJubilee == timeJubilee2) {
sprintf(txtCurTime, "%s", " bis Weihnachten ");
showText6x8(2, 0, txtTime2Wait, true);
showText6x8(2, 8, txtCurTime, true);
} else {
sprintf(txtCurTime, " %15ss", printfcomma(curTime));
showText6x8(0, 0, txtCurTime, true);
showText6x8(0, 8, txtTime2Wait, true);
if (events[currentEvent].timeEnd < timeClient.getEpochTime()) {
currentEvent++;
}
// memcpy(txtCurTimeOld, txtCurTime, 18);
// memcpy(txtTime2WaitOld, txtTime2Wait, 18);

// we don't want to miss THE EVENT
int loops = timeToWait < 60 ? 80: 15;
// Countdown bis zum nächsten Event
if (events[currentEvent].timeBegin > timeClient.getEpochTime()) {
// we don't want to miss THE EVENT
int loops = events[currentEvent].timeBegin - curTime < 60 ? 80: 15;

for (int i=0; i<loops; i++) {
long curTime = timeClient.getEpochTime();
long timeToWait = timeJubilee - curTime;
if (timeToWait < 0) {
happyDings();
break;
}
sprintf(txtTime2Wait, "Noch %12ss", printfcomma(timeToWait));
if (timeJubilee == timeJubilee2) {
sprintf(txtCurTime, "%s", " bis Weihnachten ");
showText6x8(2, 0, txtTime2Wait, true);
showText6x8(2, 8, txtCurTime, true);
} else {
sprintf(txtCurTime, " %15ss", printfcomma(curTime));
showText6x8(0, 0, txtCurTime, true);
showText6x8(0, 8, txtTime2Wait, true);
}
for (int i=0; i<loops; i++) {
curTime = timeClient.getEpochTime();
long timeToWait = events[currentEvent].timeBegin - curTime;
sprintf(txtTime2Wait, " Noch %12ss", printfcomma(timeToWait));
showText6x8(0, 0, txtTime2Wait, true);
showText6x8(0, 8, events[currentEvent].text1, true);

// for (int pos=0; pos < sizeof(txtCurTime); pos++) {
// if (txtCurTime[pos] != txtCurTimeOld[pos]) {
// showText6x8(pos*6, 0, (String)txtCurTimeOld[pos], false);
// showText6x8(pos*6, 0, (String)txtCurTime[pos], true);
// }
// if (txtTime2Wait[pos] != txtTime2WaitOld[pos]) {
// showText6x8(pos*6, 8, (String)txtTime2WaitOld[pos], false);
// showText6x8(pos*6, 8, (String)txtTime2Wait[pos], true);
// }
// }
if (timeClient.getEpochTime() - lastUpdate > 3600) {
timeClient.update();
curTime = timeClient.getEpochTime();
while (timeClient.getEpochTime() == curTime) {}
}
while (timeClient.getEpochTime() == curTime) {}
}

// memcpy(txtCurTimeOld, txtCurTime, sizeof(txtCurTime));
// memcpy(txtTime2WaitOld, txtTime2Wait, sizeof(txtTime2Wait));
// Eventtext anzeigen
if (events[currentEvent].timeBegin < timeClient.getEpochTime()) {
showText6x8(0, 0, events[currentEvent].text2, true);
showText6x8(0, 8, events[currentEvent].text3, true);
delay(15000);
}

//delay(random(MAX_PAUSE_BETWEEN_ACTIONS));
}


Expand All @@ -219,7 +209,7 @@ void happyDings() {
}
showText6x8((pos+1) * 6 , 4, "Dings!", true);
delay(5000);
timeJubilee = timeJubilee2;
//timeJubilee = timeJubilee2;
}

// custom drawing
Expand Down
20 changes: 12 additions & 8 deletions emulator/fdde.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ def readSerial():
try:
data = json.loads(data_raw)
except json.JSONDecodeError:
print (data_raw)
print(data_raw)
continue
if (not isinstance(data, dict)):
print (data_raw)
print(data_raw)
continue

try:
x = data['column']
y = data['row']
if data['status'] == 1:
color = 'yellow'
else:
color = 'black'
except KeyError:
continue
x = data['column']
y = data['row']
if data['status'] == 1:
color = 'yellow'
else:
color = 'black'

display.create_rectangle(
(x * 10 + 1, y * 10 + 1),
Expand Down