import machine
from machine import Pin
from time import sleep
from hcsr04 import HCSR04
from servo import Servo
sensor = HCSR04(trigger_pin=12, echo_pin=13, echo_timeout_us=1000000)
my_servo = Servo(machine.Pin(15))
while True:
for i in range(0,180,10):
my_servo.write_angle(i)
distance = sensor.distance_cm()
if(distance<=30):
print("Object at: "+str(i)+" distance: "+ str(distance))
sleep(0.03)
for i in range(180,0,-10):
my_servo.write_angle(i)
distance = sensor.distance_cm()
if(distance<=30):
print("Object at: "+str(i)+" distance: "+ str(distance))
sleep(0.03)