v0.55 add RTC timestamp bias correction
This commit is contained in:
parent
1bd9a30575
commit
fc9c80e320
49
dclock.ino
49
dclock.ino
|
@ -1,4 +1,4 @@
|
||||||
// Erisian digital clock - v0.5
|
// Digital erisian clock - v0.55
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <TimeLib.h>
|
#include <TimeLib.h>
|
||||||
#include <Thread.h>
|
#include <Thread.h>
|
||||||
|
@ -9,6 +9,7 @@ const byte PIN_DIO = 3; // DisplaySetting // DIO pin
|
||||||
const byte buttonPin = 4; // ButtonSetting // Button pin (a 10K resistor is necessary)
|
const byte buttonPin = 4; // ButtonSetting // Button pin (a 10K resistor is necessary)
|
||||||
SevenSegmentExtended display(PIN_CLK, PIN_DIO); // DisplaySetting
|
SevenSegmentExtended display(PIN_CLK, PIN_DIO); // DisplaySetting
|
||||||
Thread mainThread = Thread(); // mainThread
|
Thread mainThread = Thread(); // mainThread
|
||||||
|
Thread correctionThread = Thread(); // Time bias correction thread
|
||||||
long buttonPressed = 0; // Button press time counter
|
long buttonPressed = 0; // Button press time counter
|
||||||
long previousButtonMillis = 0; // Time of last button press
|
long previousButtonMillis = 0; // Time of last button press
|
||||||
byte viewMode = 0; // View mode after pressing button
|
byte viewMode = 0; // View mode after pressing button
|
||||||
|
@ -18,22 +19,25 @@ int mainCheck = 108; // The main interval is an eighth of a de
|
||||||
byte octavo = 0; // Eight-count counter
|
byte octavo = 0; // Eight-count counter
|
||||||
byte colon = 0; // Colon status
|
byte colon = 0; // Colon status
|
||||||
float erisiansec; // Erisian second
|
float erisiansec; // Erisian second
|
||||||
|
|
||||||
// Custom settings:
|
// Custom settings:
|
||||||
int brightnessPercent = 32; // Display brightness percentage value
|
int brightnessPercent = 32; // Display brightness percentage value
|
||||||
long timezoneOffset = (-28800); // Erisian timezoneOffset. Formula for calculating:
|
long timezoneOffset = (-28800); // Erisian timezoneOffset. Formula for calculating: ((-5 christian chours) - (GMT hours))
|
||||||
// ((-5 christian chours) - (GMT hours))
|
|
||||||
// Examples:
|
// Examples:
|
||||||
// GMT+3: ( (-5)-(+3) )*60*60 = -28800
|
// GMT+3: ( (-5)-(+3) )*60*60 = -28800
|
||||||
// GMT-0: ( (-5)-(0) )*60*60 = -18000
|
// GMT-0: ( (-5)-(0) )*60*60 = -18000
|
||||||
// GMT-3: ( (-5)-(-3) )*60*60 = -7200
|
// GMT-3: ( (-5)-(-3) )*60*60 = -7200
|
||||||
// GMT-5: ( (-5)-(-5) )*60*60 = 0
|
// GMT-5: ( (-5)-(-5) )*60*60 = 0
|
||||||
// GMT-7: ( (-5)-(-7) )*60*60 = 7200
|
// GMT-7: ( (-5)-(-7) )*60*60 = 7200
|
||||||
// The beginning of Discordian day (0 hours, 0 minutes,
|
// The beginning of Discordian day (0 hours, 0 minutes, 0 seconds) coincides
|
||||||
// 0 seconds) coincides with the beginning of Christian
|
// with the beginning of Christian day on Easter Island on winter time (GMT-5).
|
||||||
// day on Easter Island on winter time (GMT-5).
|
|
||||||
// Details: https://discordia.fandom.com/wiki/Erisian_Time
|
// Details: https://discordia.fandom.com/wiki/Erisian_Time
|
||||||
|
|
||||||
|
// Time bias correction variables:
|
||||||
|
int correctionBias = 11; // Daily clock correction in seconds
|
||||||
|
long correctionCheck = 300000;
|
||||||
|
byte correctionHour = 3;
|
||||||
|
bool correctionReady = true;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600); // Initializes the Serial connection @ 9600 baud for debug
|
Serial.begin(9600); // Initializes the Serial connection @ 9600 baud for debug
|
||||||
display.begin(); // Display setting, initializes the display
|
display.begin(); // Display setting, initializes the display
|
||||||
|
@ -44,19 +48,25 @@ void setup() {
|
||||||
Serial.println("Unable to sync with the RTC");
|
Serial.println("Unable to sync with the RTC");
|
||||||
display.print("_time_not_set_"); // Shows warning "time not set"
|
display.print("_time_not_set_"); // Shows warning "time not set"
|
||||||
} else {
|
} else {
|
||||||
Serial.println("RTC has set the system time");
|
// Serial.println("RTC has set the system time");
|
||||||
|
Serial.println(now());
|
||||||
display.print("HAIL_EriS"); // Shows display initialization
|
display.print("HAIL_EriS"); // Shows display initialization
|
||||||
}
|
}
|
||||||
pinMode(buttonPin, INPUT); // Button setting
|
pinMode(buttonPin, INPUT); // Button setting
|
||||||
// Main thread initialization:
|
// Main thread thread initialization:
|
||||||
mainThread.onRun(mainLoop);
|
mainThread.onRun(mainLoop);
|
||||||
mainThread.setInterval(mainCheck);
|
mainThread.setInterval(mainCheck);
|
||||||
|
// Time bias correction thread initialization:
|
||||||
|
correctionThread.onRun(correctionLoop);
|
||||||
|
correctionThread.setInterval(correctionCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Main thread:
|
// Threads:
|
||||||
if (mainThread.shouldRun())
|
if (mainThread.shouldRun())
|
||||||
mainThread.run();
|
mainThread.run();
|
||||||
|
if (correctionThread.shouldRun())
|
||||||
|
correctionThread.run();
|
||||||
// Time check:
|
// Time check:
|
||||||
if (timeStatus() != timeSet)
|
if (timeStatus() != timeSet)
|
||||||
display.print("SEt tiMe");
|
display.print("SEt tiMe");
|
||||||
|
@ -218,3 +228,22 @@ void longPress() {
|
||||||
display.print("HAIL_EriS");
|
display.print("HAIL_EriS");
|
||||||
viewMode = 0;
|
viewMode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void correctionLoop() {
|
||||||
|
if (hour() == correctionHour) {
|
||||||
|
if (correctionReady) {
|
||||||
|
// CORRECTION!
|
||||||
|
tmElements_t RTCtime;
|
||||||
|
RTC.read(RTCtime);
|
||||||
|
time_t RTCtimestamp;
|
||||||
|
RTCtimestamp = makeTime(RTCtime);
|
||||||
|
tmElements_t timeNew;
|
||||||
|
time_t newTimestamp = RTCtimestamp - correctionBias;
|
||||||
|
breakTime(newTimestamp, timeNew);
|
||||||
|
RTC.write(timeNew);
|
||||||
|
setSyncProvider(RTC.get);
|
||||||
|
// CORRECTION!
|
||||||
|
correctionReady = false;
|
||||||
|
}
|
||||||
|
} else correctionReady = true;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue