Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 299

Für den raspberry pi 4 modell b, 3 modell a +, 3 modell b +, 3 modell b, 2 modell b, 1 modell b +, 1 modell a +, zero w and zero
Inhaltsverzeichnis

Werbung

TRIG
=
16
ECHO
=
18
BUZZER
=
11
def
lcdsetup():
LCD1602.init(0x27, 1)
LCD1602.clear()
LCD1602.write(0, 0,
LCD1602.write(1, 1,
time.sleep(2)
def
setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.setup(BUZZER, GPIO.OUT, initial=GPIO.LOW)
lcdsetup()
def
distance():
GPIO.output(TRIG, 0)
time.sleep(0.000002)
GPIO.output(TRIG, 1)
time.sleep(0.00001)
GPIO.output(TRIG, 0)
while
GPIO.input(ECHO)
a
=
0
time1
=
time.time()
while
GPIO.input(ECHO)
a
=
1
time2
=
time.time()
during
=
time2
-
time1
return
during
340
*
def
destroy():
GPIO.output(BUZZER, GPIO.LOW)
GPIO.cleanup()
LCD1602.clear()
def
loop():
while
True:
dis
=
distance()
print
(dis, 'cm')
print
('')
GPIO.output(BUZZER, GPIO.LOW)
if
(dis
>
400):
LCD1602.clear()
LCD1602.write(0, 0, 'Error')
LCD1602.write(3, 1,
time.sleep(0.5)
else:
LCD1602.clear()
LCD1602.write(0, 0,
LCD1602.write(5, 1, str(round(dis,2))
if(dis>=50):
1.9. 3 Erweiterung
# init(slave address, background light)
'Ultrasonic
Starting')
'By
SunFounder')
==
0:
==
1:
/
2
100
*
'Out of
range')
'Distance
is')
SunFounder Da Vinci Kit
+'
cm')
(Fortsetzung der vorherigen Seite)
(Fortsetzung auf der nächsten Seite)
295

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis