from machine import Pin,SoftI2C
from ssd1306 import SSD1306_I2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
from time import sleep
from hcsr04 import HCSR04
sensor = HCSR04(trigger_pin=13,echo_pin=27,echo_timeout_us=20000)
i2c = SoftI2C(scl=Pin(22),sda=Pin(21),freq=100000)
I2C_ADDR = 0x3c
i2c_addr = 0x27
col=16
rows=2
oled_width = 128
oled_height = 64
oled = SSD1306_I2C(oled_width,oled_height,i2c,I2C_ADDR)
lcd= I2cLcd(i2c, i2c_addr, rows, col)
while True:
dist=sensor.distance_cm()
sleep(1)
oled.fill(0)
oled.text(str(dist),1,1)
oled.show()
lcd.putstr(str(dist))
lcd.clear()
sleep(0.3)