# from machine import Pin, I2C
# import ssd1306
# # ESP32 Pin assignment
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# oled_width = 128
# oled_height = 64
# oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
# oled.text('Hello, Wokwi!', 10, 10)
# oled.show()
# while True:
# motor1.move(0)
# motor2.move(90)
# time.sleep(0.3)
# motor1.move(0)
# motor2.move(0)
# time.sleep(0.3)
# Complete project details at https://RandomNerdTutorials.com/micropython-hc-sr04-ultrasonic-esp32-esp8266/
from hcsr04 import HCSR04
from servo import Servo
from time import sleep
# ESP32
sensor = HCSR04(trigger_pin=5, echo_pin=18, echo_timeout_us=10000)
# ESP8266
#sensor = HCSR04(trigger_pin=12, echo_pin=14, echo_timeout_us=10000)
while True:
distance = sensor.distance_cm()
print('Distance:', distance, 'cm')
if distance<=3 and distance>=0:
print('TRIGGERED')
motor1=Servo(pin=26)
motor2=Servo(pin=27)
motor1.move(0)
motor2.move(180)
sleep(0.3)
motor1.move(90)
motor2.move(90)
sleep(0.3)
sleep(1)