/ * CET DST kk99 2018 * / # include <SoftwareSerial.h> # include <TinyGPS ++. h> # include <SPI.h> # include <U8g2lib.h> # include <Timezone.h> # include <Arduino.h> // GPS TinyGPSPlus gps; // EDP U8G2_IL3820_V2_296X128_1_4W_HW_SPI u8g2 (U8G2_R0, / * cs = * / 10 , / * dc = * / 9 , / * reset = * / 8 ) ; // TimeChangeRule CEST = { "CEST" , Last, Sun, Mar, 2 , 120 }; // TimeChangeRule CET = { "CET" , Last, Sun, Oct, 3 , 60 }; // - CE (CEST, CET) ; TimeChangeRule * tcr; // SoftwareSerial softSerial ( 3 , 2 ) ; void setup () { // , : u8g2.begin (); softSerial.begin ( 9600 ); setTime ( 00 , 00 , 00 , 01 , 01 , 1970 ); } void loop () { // : readGPSData ( 1000 ); (); displayTime (); ( 59000 ); } static void readGPSData ( unsigned long timeoutMs) { unsigned long start = millis (); { while (softSerial.available ()) gps.encode (softSerial.read ()); } while (millis () - start <timeoutMs); } static void updateTime ( void ) { if (gps.time.isValid () && gps.date.isValid ()) { setTime (gps.time.hour (), gps.time.minute (), gps.time.second (), gps.date.day (), gps.date.month (), gps.date.year ()) ; } } static void displayTime ( void ) { const unsigned timeLength = 6 ; char timeValue [timeLength]; time_t utc = now (); time_t local = CE.toLocal (utc, & tcr); snprintf (timeValue, timeLength, "% 02d:% 02d" , (), ()); u8g2.firstPage (); { u8g2.setFont (u8g2_font_logisoso78_tn); u8g2.drawStr ( 26 , 103 , timeValue); } while (u8g2.nextPage ()); }
Source: https://habr.com/ru/post/450102/
All Articles