#You can simulate this code using Wokwi
# WOKWI Simulation link
#https://wokwi.com/projects/380204068912496641
from ultra import DistanceSensor
from time import sleep
#to read distance from sensor using imported ultra.py
dsa = DistanceSensor(echo=2, trigger=3)
dsb = DistanceSensor(echo=4, trigger=5)
dsc = DistanceSensor(echo=13, trigger=14)
dsd = DistanceSensor(echo=17, trigger=16)
#converting distance in terms of CM
while True:
distance_a = dsa.distance * 100
distance_b = dsb.distance * 100
distance_c = dsc.distance * 100
distance_d = dsd.distance * 100
a = float(distance_a)
b = float(distance_b)
c = float(distance_c)
d = float(distance_d)
# Convert to a floating-point number
print(a)
print(b)
print(c)
print(d)
A="A"
B="B"
C="C"
D="D"
no=0
#checking weather the slot is free of not
def parking(distance, n,slot):
if distance < 30:
# Code to execute if the distance is less than 30
print("Space is not free:"+slot)
if(n==0):
n=0
else:
n=n-1
else:
# Code to execute if the distance is not less than 30
print("Space is free: "+slot)
if(n==4):
n=4
else:
n=n+1
return n
#Printing and finding no of space Available
no=parking(a,no,A)
no=parking(b,no,B)
no=parking(c,no,C)
no=parking(d,no,D)
no=no
print("No of space available:",no)
sleep(0.1)