124 lines
3.4 KiB
C++
124 lines
3.4 KiB
C++
/* GPS_RTC_Clock
|
|
|
|
MIT License
|
|
Copyright (c) 2023 hdrlux
|
|
|
|
https://www.instructables.com/01-Sec-Accurate-RTC-GPS-Wall-Clock-Arduino-96x8-LE/
|
|
https://github.com/hdrlux/GPS_RTC_Clock
|
|
*/
|
|
|
|
#include <Arduino.h> // needed for Nano Every
|
|
#include "GPS_RTC_Clock.h"
|
|
//#include "LED_96x8_matrix.h"
|
|
#include <DMD2.h>
|
|
#include <LiquidCrystal_I2C.h>
|
|
#include "Font_Chrono1.h"
|
|
|
|
#define pin_RTC_SQW 3
|
|
#define DEBUG_PORT Serial
|
|
|
|
SoftDMD dmd(2, 1);
|
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
|
|
char TempBuf[5] = "99.9"; // demo value
|
|
char HumiBuf[3] = "99"; // demo value
|
|
|
|
unsigned long TMR_FPS;
|
|
long FPS;
|
|
|
|
bool LCD_Simple_clock;
|
|
|
|
void setup() { // the setup function runs once when you press reset or power the board
|
|
// LCD
|
|
lcd.init(); // Инициализация дисплея
|
|
lcd.clear();
|
|
lcd.backlight();
|
|
lcd.setCursor(0,0);
|
|
lcd.print("DEBUG[setup()]");
|
|
DEBUG_PORT.begin(38400);
|
|
DEBUG_PORT.flush();
|
|
delay(1000);
|
|
DEBUG_PORT.println("DEBUG[setup()]");
|
|
//Serial.begin(19200); // = 9600, must be same as GPS for debug
|
|
//Serial.println(); // flush serial
|
|
//Serial.println("-Arduino Reboot-"); // debug
|
|
|
|
GPS_RTC_Clock_setup(); // first in setup
|
|
//Matrix_setup(); // LED display
|
|
//dmd.setBrightness(5);
|
|
//dmd.selectFont(Font_Chrono1);
|
|
//dmd.begin();
|
|
//dmd.clearScreen();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print(" ");
|
|
}
|
|
|
|
void loop() { // the loop function runs over and over again forever
|
|
// if (millis() - tmr_Blink > 500) {
|
|
// Serial.println("DEBUG[BLINK] " + int(digitalRead(13)));
|
|
// tmr_Blink = millis();
|
|
// digitalWrite(13, !digitalRead(13));
|
|
// }
|
|
|
|
GPS_RTC_Clock_loop(); // first in loop
|
|
|
|
RTCtoLCD();
|
|
//chkFPS();
|
|
}
|
|
|
|
/////////////////////
|
|
void RTCtoLCD() {
|
|
/*if (GPS_sec) {
|
|
DEBUG_PORT.println("DEBUG[RTCtoLCD] GPS_sec");
|
|
GPS_PPS_LCD = !GPS_PPS_LCD;
|
|
lcd.setCursor(2, 0);
|
|
lcd.print((GPS_PPS_LCD) ? " " : ":");
|
|
}
|
|
if (RTC_sec) {
|
|
DEBUG_PORT.println("DEBUG[RTCtoLCD] RTC_sec");
|
|
RTC_SQW_LCD = !RTC_SQW_LCD;
|
|
lcd.setCursor(5, 0);
|
|
lcd.print((RTC_SQW_LCD) ? " " : ":");
|
|
}*/
|
|
//if (!GPS_sec and !RTC_sec) return;
|
|
if (!NewSec && !NewMin && !NewHour) return;
|
|
char Clock[9];
|
|
char segment[3];
|
|
char message[50];
|
|
|
|
if (NewSec) {
|
|
DEBUG_PORT.println("DEBUG[RTCtoLCD] newSec");
|
|
//DEBUG_PORT.println("DEBUG[RTCtoLCD] RTCMillis: " + String(RTCMillis));
|
|
//DEBUG_PORT.println("DEBUG[RTCtoLCD] RTC_sec: " + String(RTC_sec));
|
|
//DEBUG_PORT.println("DEBUG[RTCtoLCD] millis: " + String(millis()));
|
|
//snprintf(segment, sizeof(segment),"%.2u", second(Loc_t));
|
|
snprintf(segment, sizeof(segment),"%.2u", second(RTC_t));
|
|
lcd.setCursor(6, 0);
|
|
lcd.print(segment);
|
|
}
|
|
|
|
if (NewMin) {
|
|
//snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
|
|
snprintf(segment, sizeof(segment),"%.2u", minute(RTC_t));
|
|
lcd.setCursor(3, 0);
|
|
lcd.print(segment);
|
|
//snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
|
|
snprintf(segment, sizeof(segment),"%.2u", hour(RTC_t));
|
|
lcd.setCursor(0, 0);
|
|
lcd.print(segment);
|
|
}
|
|
}
|
|
|
|
void chkFPS() {
|
|
if (micros() - TMR_FPS > 1000000) {
|
|
DEBUG_PORT.println("DEBUG[chkFPS] FPS: " + String(FPS));
|
|
//DEBUG_PORT.println("DEBUG[chkFPS] TMR_FPS: " + String(TMR_FPS));
|
|
TMR_FPS = micros();
|
|
FPS = 0;
|
|
return;
|
|
}
|
|
FPS++;
|
|
}
|
|
|
|
//End
|