🎉 Inits web
All checks were successful
Gitea Build Action / build (push) Successful in 36s

This commit is contained in:
Daniel Svitan
2025-06-04 21:38:24 +02:00
parent 7d2ad1cd49
commit 00bf392931
15 changed files with 2161 additions and 1 deletions

View File

@@ -105,20 +105,28 @@ class App:
except Exception as e:
print(f"Error occurred: {e}")
def measure_distance(self):
def measure_distance(self) -> float:
self.trigger.low()
utime.sleep_us(2)
self.trigger.high()
utime.sleep_us(10)
self.trigger.low()
start_time = utime.ticks_us()
sent_time = utime.ticks_us()
while self.echo.value() == 0:
print("hey", end="\r")
sent_time = utime.ticks_us()
if sent_time - start_time >= 100_000: # if it takes more than 100ms, stop
return -1
start_time = utime.ticks_us()
received_time = utime.ticks_us()
while self.echo.value() == 1:
print("ho", end="\r")
received_time = utime.ticks_us()
if received_time - start_time >= 100_000: # same
return -1
delta_time = received_time - sent_time
distance = delta_time / 1_000_000 * SOUND_SPEED / 2
@@ -170,5 +178,6 @@ class App:
i += 1
if __name__ == "__main__":
App().run()