import time
import random
from machine import I2C , Pin , SoftI2C , RTC
from pico_i2c_lcd import I2cLcd
print("Hello, Pi Pico!")
i2c = SoftI2C(sda=Pin(0),scl=Pin(1),freq=40000)
print(hex(i2c.scan()[0]))
devices = i2c.scan()
for device in devices:
print(hex(device))
lcd = I2cLcd(i2c, devices[0] , 2 , 16)
lcd.clear()
# red_led = Pin(5,Pin.OUT)
# yellow_led = Pin(9,Pin.OUT)
# green_led = Pin(13,Pin.OUT)
# red_led.on()
# for i in range(10,0,-1):
# lcd.putstr(f"{i} secs")
# time.sleep(1)
# lcd.clear()
# red_led.off()
# green_led.on()
# for i in range(10,0,-1):
# lcd.putstr(f"{i} secs")
# time.sleep(1)
# lcd.clear()
# green_led.off()
# yellow_led.on()
# for i in range(10,0,-1):
# lcd.putstr(f"{i} secs")
# time.sleep(1)
# lcd.clear()
# yellow_led.off()
# def traffic_signal():
# x=random.random()
# if x>0.75:
# red_led.on()
# for i in range(10,0,-1):
# lcd.putstr(f"{i} secs")
# time.sleep(1)
# lcd.clear()
# red_led.off()
# elif x>0.5:
# yellow_led.on()
# for i in range(10,0,-1):
# lcd.putstr(f"{i} secs")
# time.sleep(1)
# lcd.clear()
# yellow_led.off()
# else:
# green_led.on()
# for i in range(10,0,-1):
# lcd.putstr(f"{i} secs")
# time.sleep(1)
# lcd.clear()
# green_led.off()
# while 1:
# traffic_signal()
# lcd = I2cLcd(i2c, devices[0] , 2 , 16)
# lcd.clear()
# lcd.move_to(5,1)
# lcd.putstr("Hello !")
# time.sleep(2)
# lcd.clear()
rtc = RTC()
rtc.datetime((2024,1,24,5,11,21,0,0))
time.sleep(1.5)
print(rtc.datetime())
lcd.putstr(f"{rtc.datetime()}")
time.sleep(2.5)
print(rtc.datetime())
lcd.clear()
lcd.putstr(f"{rtc.datetime()}")