File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright (c) 2021 John Park for Adafruit
2+ #
3+ # SPDX-License-Identifier: MIT
4+ # FunHouse Parking Assistant
5+
6+ import time
7+ import board
8+ import adafruit_hcsr04
9+ import neopixel
10+ from adafruit_funhouse import FunHouse
11+
12+ SLOW_DISTANCE = 30 # distance (in centimeters) when you should slow
13+ STOP_DISTANCE = 8 # distance when you should hit those brakes
14+
15+ GREEN = 0x00FF00
16+ AMBER = 0xF0D000
17+ RED = 0xFF0000
18+
19+
20+ funhouse = FunHouse (default_bg = None , scale = 3 )
21+ funhouse .peripherals .dotstars .brightness = 0.05
22+ funhouse .peripherals .dotstars .fill (GREEN )
23+
24+ pixel_pin = board .A2
25+ num_pixels = 30
26+ pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 0.3 , auto_write = False )
27+
28+ sonar = adafruit_hcsr04 .HCSR04 (trigger_pin = board .A0 , echo_pin = board .A1 )
29+
30+ while True :
31+ try :
32+ print ((sonar .distance ,))
33+
34+ if sonar .distance > SLOW_DISTANCE :
35+ funhouse .peripherals .dotstars .fill (GREEN )
36+ pixels .fill (GREEN )
37+ pixels .show ()
38+ elif sonar .distance < SLOW_DISTANCE and sonar .distance > STOP_DISTANCE :
39+ funhouse .peripherals .dotstars .fill (AMBER )
40+ pixels .fill (AMBER )
41+ pixels .show ()
42+ funhouse .peripherals .play_tone (1000 , 0.3 )
43+ elif sonar .distance < STOP_DISTANCE :
44+ funhouse .peripherals .dotstars .fill (RED )
45+ pixels .fill (RED )
46+ pixels .show ()
47+ funhouse .peripherals .play_tone (2600 , 0.3 )
48+
49+ except RuntimeError :
50+ print ("Retrying!" )
51+ time .sleep (0.01 )
You can’t perform that action at this time.
0 commit comments