from machine import I2C, Pin
import time
from ds1307 import DS1307
from i2c_lcd import I2cLcd
# ---------------- I2C ----------------
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=100000)
time.sleep(1)
print("==============================")
print(" Hello Smart-ENEng. of RMUTI ")
print("==============================")
# ---------------- LCD ----------------
lcd = I2cLcd(i2c, 0x27, 20, 4)
# ---------------- RTC ----------------
rtc = DS1307(i2c)
# ตั้งเวลา RTC ครั้งแรก
rtc.set_time(2026, 3, 12, 4, 09, 27, 0)
dt = rtc.datetime()
# ---------------- Welcome Screen ----------------
lcd.clear()
lcd.move_to(2,1)
lcd.putstr("Hello Smart-ENEng")
lcd.move_to(7,2)
lcd.putstr("RMUTI")
time.sleep(3)
lcd.clear()
# ---------------- Main Loop ----------------
while True:
dt = rtc.datetime()
year = dt[0]
month = dt[1]
day = dt[2]
hour = dt[3]
minute= dt[4]
sec = dt[6]
lcd.move_to(0,0)
lcd.putstr(" Smart ENEng System ")
lcd.move_to(0,1)
lcd.putstr("Date: {:02d}/{:02d}/{:04d}".format(day, month, year))
lcd.move_to(0,2)
lcd.putstr("Time: {:02d}:{:02d}:{:02d}".format(hour, minute, sec))
lcd.move_to(0,3)
lcd.putstr(" RMUTI Engineering ")
print("Date: {:02d}/{:02d}/{:04d}".format(day, month, year))
print("Time: {:02d}:{:02d}:{:02d}".format(hour, minute, sec))
print("--------------------------")
time.sleep(1)