from machine import Pin
import utime
t1=Pin(22,Pin.OUT)
e1=Pin(21,Pin.IN)
buz=Pin(6,Pin.OUT)
c=0
while True:
#getting values from ultra sonic sensor
t1.low()
utime.sleep_us(2)
t1.high()
utime.sleep_us(5)
t1.low()
while e1.value()==0:
sigoff=utime.ticks_us()
while e1.value()==1:
sigon=utime.ticks_us()
tp1=sigon-sigoff
dist1=(tp1*0.0343)/2
#computing the movement of vehicle
if dist1<=100:
c=c+1
else:
if c!=0:
c=c-1
else:
c=0
print("=============================")
print("No of vehicles Passed", c)
#predicting the traffic of next junction
#with number of current junction vehicles
if c<10:
print("Happy Journey\n\n")
if c>=10 and c<15:
print("Chance of increase in traffic\n\n")
if c>=15:
print("High traffic alert\n\n")
utime.sleep(1)