import time
import machine
from machine import Pin ,I2C, SoftI2C,Timer,RTC,PWM, ADC
from pico_i2c_lcd import I2cLcd
i2c=SoftI2C(sda=Pin(6),scl=Pin(5),freq=400000)
addr=i2c.scan()[0]
lcd=I2cLcd(i2c,addr,2,16)
rtc= RTC()
rtc.datetime((2024,2,2,6,11,10,0,0)) #get or set the current time
# print(rtc.datetime())
# print(time.tick_ms())
motor = PWM(Pin(0))
motor.freq(50)
verticle = ADC(26)
horizontal = ADC(27)
select = Pin(28,Pin.IN,Pin.PULL_DOWN)
def displayTime():
lcd.putstr(str(rtc.datetime()[4])+":"+str(rtc.datetime()[5])+":"+str(rtc.datetime()[6]))
time.sleep(1)
lcd.clear()
position = 4500
while True:
if select.value()==1:
print("Clicked")
b=0
while verticle.read_u16()<32759 and position<4750:
position+=1
motor.duty_u16(position)
b=1
if b==1 :
time.sleep(1)
lcd.putstr("gate opened at : ")
displayTime()
b=0
while verticle.read_u16()>32759 and position>1001:
position-=1
motor.duty_u16(position)
b=2
if b==2 :
time.sleep(1)
lcd.putstr("gate closed at : ")
displayTime()
b=0
time.sleep(1)