import time
from machine import I2C, SoftI2C, Pin, RTC
#I2C and softI2c is interchangable
#RTC real time clock
from pico_i2c_lcd import I2cLcd
i2c = SoftI2C(sda=Pin(0), scl=Pin(27), freq=40000)
#sda:
#scl:
#freq is given in docs
lcd_addr = i2c.scan()[0]
#it will return a list of addresses
print(lcd_addr)
lcd = I2cLcd(i2c, lcd_addr, 2, 16)
#parameters: protocol name, address, rows, cols
#Q1: display message**********************
# lcd.clear()
# lcd.move_to(3, 1)
# lcd.putstr("hello aish")
# time.sleep(2)
# Q2: display table of 2************************
# lcd.clear()
# lcd.move_to(0, 0)
# i=1
# while(i<11):
# lcd.move_to(3,1)
# p=2*i
# s="2*"+str(i)+"="+str(p)
# lcd.putstr(s)
# i=i+1
# time.sleep(2)
# lcd.clear()
# Q2: display date
rtc = RTC()
rtc.datetime((2024, 2, 9, 5, 1, 0, 0, 0)) #set
#year, month, sdate, weekday, hour, min, sec, microsec
time.sleep(1)
print(rtc.datetime()) #get
# rtc.datetime can either get or set the clock
while(1):
lcd.move_to(0,0) #row, col
p=rtc.datetime()
ans=""
for r in p:
ans+=str(r)+":"
lcd.putstr(ans)
time.sleep(3)
lcd.clear()