from machine import Pin, SoftI2C
import oled
import utime
from rtc import RTC
# Setup I2C
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=100000)
devices = i2c.scan()
print("Found I2C devices:", devices)
# OLED at 0x3C
if 0x3C in devices:
oled_display = oled.SSD1306_I2C(128, 64, i2c, addr=0x3C)
oled_display.fill(0)
oled_display.text("Welcome!", 35, 20)
oled_display.show()
utime.sleep(2)
else:
print("OLED not found!")
if 0x68 in devices:
rtc = RTC(i2c)
else:
print("RTC not found!")
while True:
date = rtc.get_date_string()
time = rtc.get_time_string()
oled_display.fill(0)
oled_display.text(date, 22, 20)
oled_display.text(time, 30, 40)
oled_display.show()
utime.sleep(1)