#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
// initialize the library with the I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 20, 4);
RTC_DS3231 rtc;
void setup() {
lcd.init(); // initialize the LCD
lcd.backlight(); // turn on the backlight
if (!rtc.begin()) {
lcd.print("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
// Set the time to a specific date & time, e.g., when the sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
// text to display
String text = "SELAMAT DATANG DI SMAN 57";
int textLength = text.length();
// Get current time
DateTime now = rtc.now();
char currentTime[9];
sprintf(currentTime, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
// loop to create running text effect
for (int i = 0; i < textLength + 20; i++) {
lcd.clear();
lcd.setCursor(20 - i, 0); // Adjust the row (0-3) as needed for running text
lcd.print(text);
lcd.setCursor(0, 3); // Adjust the row (0-3) as needed for time
lcd.print(currentTime);
delay(300);
}
}