from machine import Pin,PWM
from time import sleep
#Servo motor-5-yello,red-+,brown--
servo0 = PWM(Pin(22),freq=50)
min_duty = 26
max_duty = 123
mid_duty = min_duty+(max_duty - min_duty)//2
current_duty = min_duty
#Pins(5-yellow||12,13,14,15,16,17-Tx2||22,23,25,26,27||32,33)
#IR
ir0a=1
ir0b=0
ir = [0,0,0,0]
none = 0
#LED
led0a=0
led = [0,0,0,0]
#servoMotor_Function
def servoAction():
led0a=1
print("led0a_on")
sleep(3)
servo0.duty(current_duty)
sleep(3)
servo0.duty(mid_duty)
sleep(3)
led0a=0
print("led0a_off")
#Parking Slot Status
def SlotStatus(slot,ledNum):
lNum = int(ledNum)
#lcd.move_to(0,0)
print(" welcome\n")
print("Go to Slot "+ str(slot))
led[lNum]=1
print("Num " + str(ledNum))
sleep(1.5)
servoAction()
if(led[lNum]==0):
print("off")
if(led[lNum]==1):
print("on")
sleep(1)
#lcd.clear()
while 1:
#lcd.move_to(0,0)
print(" welcome\n")
for i in range(len(ir)):
if ir[i]== 0:
#sleep(0.2)
led[i]=0
if ir0a==0:
#lcd.move_to(0,0)
print(" welcome\n")
sleep(0.2)
#lcd.clear()
if ir[0]==1 and led[0]==0:
SlotStatus("A-01",0)
continue
if ir[1]==1 and led[1]==0:
SlotStatus("A-02",1)
continue
if ir[2]==1 and led[2]==0:
SlotStatus("A-03",2)
continue
if ir[3]==1 and led[3]==0:
SlotStatus("A-04",3)
continue
if none == 0:
print("welcome Sorry \n")
print("No free slot")
sleep(3)
#lcd.clear()
continue
if ir0b == 0:
servoAction()