Traceback (most recent call last):
File "main.py", line 27, in <module>
File "adafruit_hcsr04.py", line 127, in distance
File "adafruit_hcsr04.py", line 144, in _dist_two_wire
RuntimeError: Timed out
Code: Select all
import time
import board
import adafruit_hcsr04
from neopixel import NeoPixel
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.color import PURPLE, ORANGE
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D2, echo_pin=board.D3)
pixels = NeoPixel(board.D1, 60, brightness=1, auto_write=True)
def show_comet(val):
if(val > -1 and val <= 6):
comet.animate()
if(val > 6 and val < 12):
comet1.animate()
if(val > 12 and val < 18):
comet.animate()
if(val > 24 and val < 30):
comet1.animate()
if(val > 24 and val < 30):
comet.animate()
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
comet1 = Comet(pixels, speed=0.01, color=ORANGE, tail_length=10, bounce=True)
while True:
show_comet(sonar.distance)
try:
print((sonar.distance))
except RuntimeError:
print("error")
time.sleep(0.1)