def main():
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
from oledhelper import oledClear, oledPrint
from imu import MPU6050
import time
trig=Pin(2,Pin.OUT,0)
echo=Pin(3,Pin.IN)
btn1=Pin(13,Pin.IN,Pin.PULL_UP)
while True:
trig.value(0)
time.sleep_ms(20)
trig.value(1)
time.sleep_ms(10)
trig.value(0)
print("B")
while echo.value() == 0:
pass
Start =time.ticks_ms()
#print(f'{Ende}')
print("C")
while echo.value() == 1:
pass
Ende=time.ticks_ms()
print("D")
Dauer=time.ticks_diff(Ende,Start)
Abstand = 34.2*Dauer*0.5
print(f'Abstand: {Abstand:.3f} cm' )
main()