# Import necessary libraries
from machine import Pin, SoftI2C
from utime import sleep_ms, sleep
from hcsr04 import HCSR04
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
# Initialize LCD
i2c = SoftI2C(sda=Pin(21), scl=Pin(22))
lcd = I2cLcd(i2c, 0x27, 2, 16) # Adjust address and rows/columns if needed
# Initialize Ultrasonic Sensor
trig_pin = Pin(12, Pin.OUT)
echo_pin = Pin(14, Pin.IN)
ultrasonic = HCSR04(trig_pin, echo_pin)
# Main loop
while True:
# Read distance
distance = ultrasonic.distance_cm()
# Display the distance on the Serial monitor for validation
print("Distance: %.2f cm" % distance)
#LCD display
lcd.move_to(0,0)
lcd.putstr('Distance: ')
lcd.move_to(0,1)
lcd.putstr('%.2f cm' % distance)
sleep(5)