WIP
рабочий код. отображение часов согласно часового пояса MSK на LCD. GPS(19200) и RTC работают.
This commit is contained in:
@@ -19,26 +19,59 @@
|
||||
SoftDMD dmd(2, 1);
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||
|
||||
unsigned long tmr_Blink;
|
||||
|
||||
char TempBuf[5] = "99.9"; // demo value
|
||||
char HumiBuf[3] = "99"; // demo value
|
||||
|
||||
bool LCD_Simple_clock;
|
||||
|
||||
void RTCtoLCD(bool ClockType = LCD_Simple_clock) {
|
||||
if (millis() < 2000) ClockType = true;
|
||||
else if (!NewSec && !NewMin && !NewHour) return;
|
||||
char Clock[9];
|
||||
char segment[3];
|
||||
|
||||
if (ClockType) {
|
||||
snprintf(Clock, sizeof(Clock), "%.2u:%.2u:%.2u", hour(Loc_t), minute(Loc_t), second(Loc_t));
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print(Clock);
|
||||
}
|
||||
else if (NewSec) {
|
||||
snprintf(segment, sizeof(segment),"%.2u", second(Loc_t));
|
||||
lcd.setCursor(6, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
if (NewMin) {
|
||||
snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
|
||||
lcd.setCursor(3, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
if (NewHour) {
|
||||
snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(segment);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() { // the setup function runs once when you press reset or power the board
|
||||
GPS_RTC_Clock_setup(); // first in setup
|
||||
//Matrix_setup(); // LED display
|
||||
dmd.setBrightness(5);
|
||||
dmd.selectFont(Font_Chrono1);
|
||||
dmd.begin();
|
||||
dmd.clearScreen();
|
||||
// LCD
|
||||
lcd.init(); // Инициализация дисплея
|
||||
lcd.clear();
|
||||
lcd.backlight();
|
||||
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print("DEBUG[setup()]");
|
||||
delay(500);
|
||||
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
|
||||
@@ -49,18 +82,9 @@ void loop() { // the loop function runs over and over again forever
|
||||
// }
|
||||
|
||||
GPS_RTC_Clock_loop(); // first in loop
|
||||
//PrintSec();
|
||||
//PrintHour();
|
||||
if (NewSec) {
|
||||
RTCtoLCD();
|
||||
}
|
||||
}
|
||||
|
||||
void RTCtoLCD() {
|
||||
char sz[32];
|
||||
sprintf(sz, "%02d:%02d:%02d ", hour(Loc_t), minute(Loc_t), second(Loc_t));
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print(sz);
|
||||
RTCtoLCD();
|
||||
PrintSec();
|
||||
PrintHour();
|
||||
}
|
||||
|
||||
void PrintSec() { // print time if new second
|
||||
@@ -68,16 +92,16 @@ void PrintSec() { // print time if new second
|
||||
NewSec = false; // remove flag, do only once every sec
|
||||
char startmarker = '<';
|
||||
char endmarker = '>';
|
||||
Serial.print(startmarker); // for remote display via RS485
|
||||
Serial.print(Loc_t); // for remote display via RS485
|
||||
Serial.println(endmarker); // for remote display via RS485
|
||||
//Serial.print(startmarker); // for remote display via RS485
|
||||
//Serial.print(Loc_t); // for remote display via RS485
|
||||
//Serial.println(endmarker); // for remote display via RS485
|
||||
|
||||
char TimeBuf[9]; // time string buffer, max n-1 char
|
||||
snprintf(TimeBuf, sizeof(TimeBuf), "%.2u:%.2u:%.2u", // https://cplusplus.com/reference/cstdio/printf/
|
||||
hour(Loc_t), minute(Loc_t), second(Loc_t)); // time 24h format
|
||||
Serial.print("Time: "); // debug
|
||||
Serial.println(TimeBuf); // debug
|
||||
Print_time_zone(TimeBuf); // print to LED Matrix
|
||||
//Serial.print("Time: "); // debug
|
||||
//Serial.println(TimeBuf); // debug
|
||||
//Print_time_zone(TimeBuf); // print to LED Matrix
|
||||
PrintMin();
|
||||
}
|
||||
}
|
||||
@@ -109,7 +133,7 @@ void PrintMin() {
|
||||
snprintf(TextBuf, sizeof(TextBuf), " Err ");
|
||||
}
|
||||
}
|
||||
Print_date_zone(TextBuf); // print to LED Matrix
|
||||
//Print_date_zone(TextBuf); // print to LED Matrix
|
||||
|
||||
if (NewMin) { // print date if new minute
|
||||
NewMin = false; // remove flag, do only once every min
|
||||
@@ -117,15 +141,15 @@ void PrintMin() {
|
||||
// long date version
|
||||
snprintf(DateBuf, sizeof(DateBuf), "%s %.2u-%s-%u W%.2u",
|
||||
dayShortStrLoc(weekday(Loc_t)), day(Loc_t), monthShortStrLoc(month(Loc_t)), year(Loc_t), ISOWeekNumber(Loc_t));
|
||||
Serial.print("Date long: "); // debug
|
||||
Serial.println(DateBuf); // debug
|
||||
//Serial.print("Date long: "); // debug
|
||||
//Serial.println(DateBuf); // debug
|
||||
}
|
||||
}
|
||||
|
||||
void PrintHour() { // do if new hour
|
||||
if (NewHour) { //
|
||||
NewHour = false; // remove flag, do only once every hour
|
||||
Serial.println("bring out the Cuckoo ;-)"); // debug
|
||||
//Serial.println("bring out the Cuckoo ;-)"); // debug
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user