From aa518823248dfe0310203bab0e95689a0c874558 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 2 Nov 2021 15:36:34 +0100 Subject: [PATCH] Initial Release --- hcsr04.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 hcsr04.py diff --git a/hcsr04.py b/hcsr04.py new file mode 100755 index 0000000..677cb49 --- /dev/null +++ b/hcsr04.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import time +import board +import adafruit_hcsr04 + +sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D5, echo_pin=board.D6) + +while True: + try: + print("Distance: %.2f cm" % sonar.distance) + except RuntimeError: + print("Retrying!") + time.sleep(0.1)