from machine import Pin
import utime
trigger = Pin(14, Pin.OUT)
echo = Pin(15, Pin.OUT)
a = Pin(1, Pin.OUT)
b = Pin(2, Pin.OUT)
c = Pin(3, Pin.OUT)
d = Pin(4, Pin.OUT)
e = Pin(5, Pin.OUT)
f = Pin(6, Pin.OUT)
g = Pin(7, Pin.OUT)
def ultra():
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(5)
trigger.low()
while echo.value() == 0:
signaloff = utime.ticks_us()
while echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon - signaloff
distance = (timepassed * 0.0343) / 2
print("The distance from object is",distance,"cm")
if distance > 10:
print("1")
c = 1
if distance > 20:
print("2")
c = 2
if distance > 30:
print("3")
c = 3
if distance > 40:
print("4")
c = 4
if distance > 50:
print("5")
c = 5
if distance > 60:
print("6")
c = 6
if distance > 70:
print("7")
c = 7
if distance > 80:
print("8")
c = 8
if distance > 90:
print("9")
c = 9
if distance > 100:
print("0")
c = 0
return c
while True:
y = ultra()
utime.sleep(1)
if y == 1:
a.high()
d.high()
e.high()
f.high()
g.high()
b.low()
c.low()
elif y == 2:
c.high()
f.high()
a.low()
b.low()
g.low()
e.low()
d.low()
elif y == 3:
e.high()
f.high()
a.low()
b.low()
g.low()
c.low()
d.low()
elif y == 4:
e.high()
d.high()
a.high()
f.low()
g.low()
b.low()
c.low()
elif y == 5:
b.high()
e.high()
a.low()
f.low()
g.low()
c.low()
d.low()
elif y == 6:
b.high()
a.low()
f.low()
e.low()
d.low()
c.low()
g.low()
elif y == 7:
f.high()
g.high()
e.high()
d.low()
a.low()
b.low()
c.low()
elif y == 8:
a.low()
b.low()
c.low()
d.low()
e.low()
f.low()
g.low()
elif y == 9:
e.high()
d.high()
a.low()
f.low()
g.low()
b.low()
c.low()
elif y == 0:
g.high()
a.low()
b.low()
c.low()
d.low()
e.low()
f.low()