Robotex-Rally/sensortest-rally.py
2025-05-24 03:34:20 +03:00

14 lines
No EOL
284 B
Python

import time
import board
import adafruit_hcsr04
# Set the sensor pins
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.TRIG, echo_pin=board.ECHO)
while True:
try:
print(f"{sonar.distance:.2f}")
except RuntimeError:
print("Retrying!")
time.sleep(0.1)