#include #include "PCF85063TP.h" #include "rgb_lcd.h" //Library // Grove High Precission RTC (Seeed Studio) // Grove LCD RGB Backlight (Seeed Studio) // Adafruit DS248x I2C Communicatie PCD85063TP clock; rgb_lcd lcd; void setup() { Serial.begin(9600); Wire.begin(); // 1. Initialiseer LCD lcd.begin(16, 2); lcd.setRGB(50, 50, 255); // Blauwe achtergrond tijdens instellen lcd.print("RTC Syncen..."); // 2. Initialiseer RTC clock.begin(); // Haal PC tijd op (__DATE__ en __TIME__) char m[4]; int d, y, hh, mm, ss; sscanf(__DATE__, "%s %d %d", m, &d, &y); sscanf(__TIME__, "%d:%d:%d", &hh, &mm, &ss); const char *monthNames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; int monthIndex = 0; for (int i = 0; i < 12; i++) { if (strcmp(m, monthNames[i]) == 0) { monthIndex = i + 1; break; } } // Schrijf de PC tijd naar de RTC chip clock.stopClock(); clock.fillByYMD(y, monthIndex, d); clock.fillByHMS(hh, mm, ss); clock.setTime(); clock.startClock(); Serial.println("RTC gesynchroniseerd!"); lcd.clear(); lcd.setRGB(0, 255, 0); // Groen als het klaar is } void loop() { // Stap 1: Lees de tijd van de RTC clock.getTime(); // Stap 2: Schrijf naar het LCD // Datum op regel 1 lcd.setCursor(0, 0); lcd.print("D: "); if(clock.dayOfMonth < 10) lcd.print('0'); lcd.print(clock.dayOfMonth); lcd.print("-"); if(clock.month < 10) lcd.print('0'); lcd.print(clock.month); lcd.print("-"); lcd.print(clock.year + 2000); // Tijd op regel 2 lcd.setCursor(0, 1); lcd.print("T: "); if(clock.hour < 10) lcd.print('0'); lcd.print(clock.hour); lcd.print(":"); if(clock.minute < 10) lcd.print('0'); lcd.print(clock.minute); lcd.print(":"); if(clock.second < 10) lcd.print('0'); lcd.print(clock.second); delay(1000); // Update elke seconde }