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 <TimeLib.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)
|
||||
SevenSegmentExtended display(PIN_CLK, PIN_DIO); // DisplaySetting
|
||||
Thread mainThread = Thread(); // mainThread
|
||||
Thread correctionThread = Thread(); // Time bias correction thread
|
||||
long buttonPressed = 0; // Button press time counter
|
||||
long previousButtonMillis = 0; // Time of last button press
|
||||
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 colon = 0; // Colon status
|
||||
float erisiansec; // Erisian second
|
||||
|
||||
// Custom settings:
|
||||
int brightnessPercent = 32; // Display brightness percentage value
|
||||
long timezoneOffset = (-28800); // Erisian timezoneOffset. Formula for calculating:
|
||||
// ((-5 christian chours) - (GMT hours))
|
||||
long timezoneOffset = (-28800); // Erisian timezoneOffset. Formula for calculating: ((-5 christian chours) - (GMT hours))
|
||||
// Examples:
|
||||
// GMT+3: ( (-5)-(+3) )*60*60 = -28800
|
||||
// GMT-0: ( (-5)-(0) )*60*60 = -18000
|
||||
// GMT-3: ( (-5)-(-3) )*60*60 = -7200
|
||||
// GMT-5: ( (-5)-(-5) )*60*60 = 0
|
||||
// GMT-7: ( (-5)-(-7) )*60*60 = 7200
|
||||
// The beginning of Discordian day (0 hours, 0 minutes,
|
||||
// 0 seconds) coincides with the beginning of Christian
|
||||
// day on Easter Island on winter time (GMT-5).
|
||||
// The beginning of Discordian day (0 hours, 0 minutes, 0 seconds) coincides
|
||||
// with the beginning of Christian day on Easter Island on winter time (GMT-5).
|
||||
// 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() {
|
||||
Serial.begin(9600); // Initializes the Serial connection @ 9600 baud for debug
|
||||
display.begin(); // Display setting, initializes the display
|
||||
|
@ -44,19 +48,25 @@ void setup() {
|
|||
Serial.println("Unable to sync with the RTC");
|
||||
display.print("_time_not_set_"); // Shows warning "time not set"
|
||||
} 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
|
||||
}
|
||||
pinMode(buttonPin, INPUT); // Button setting
|
||||
// Main thread initialization:
|
||||
// Main thread thread initialization:
|
||||
mainThread.onRun(mainLoop);
|
||||
mainThread.setInterval(mainCheck);
|
||||
// Time bias correction thread initialization:
|
||||
correctionThread.onRun(correctionLoop);
|
||||
correctionThread.setInterval(correctionCheck);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Main thread:
|
||||
// Threads:
|
||||
if (mainThread.shouldRun())
|
||||
mainThread.run();
|
||||
if (correctionThread.shouldRun())
|
||||
correctionThread.run();
|
||||
// Time check:
|
||||
if (timeStatus() != timeSet)
|
||||
display.print("SEt tiMe");
|
||||
|
@ -218,3 +228,22 @@ void longPress() {
|
|||
display.print("HAIL_EriS");
|
||||
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