Herunterladen Inhalt Inhalt Diese Seite drucken

Code Erklärung - SunFounder Da Vinci Kit Bedienungsanleitung

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

SunFounder Da Vinci Kit
p
=
GPIO.PWM(servoPin, 50)
p.start(0)
map(value, inMin, inMax, outMin, outMax):
def
return
(outMax
def
setAngle(angle):
angle
=
max(0, min(180, angle))
pulse_width
=
map(angle, 0, 180, SERVO_MIN_PULSE, SERVO_MAX_PULSE)
pwm
=
map(pulse_width, 0, 20000, 0, 100)
p.ChangeDutyCycle(pwm)#map the angle to duty cycle and output it
def
doorbell():
for
i
in
range(1, len(song)):
Buzz.ChangeFrequency(song[i])
time.sleep(beat[i]
time.sleep(1)
def
closedoor():
GPIO.output(ledPin, GPIO.LOW)
for
i
in
range(180, -1, -1):
setAngle(i)
time.sleep(0.001)
time.sleep(1)
def
opendoor():
GPIO.output(ledPin, GPIO.LOW)
for
i
in
range(0, 181, 1):
setAngle(i)
time.sleep(0.001)
time.sleep(1)
doorbell()
closedoor()
def
loop():
while
True:
if
GPIO.input(pirPin)==GPIO.HIGH:
opendoor()
def
destroy():
GPIO.cleanup()
p.stop()
Buzz.stop()
if
__name__
==
'__main__':
setup()
try:
loop()
except
KeyboardInterrupt:
be
executed.
destroy()
Code Erklärung
def
setup():
global
p
286
# set Frequece to 50Hz
# Duty Cycle = 0
-
outMin)
(value
*
# make the servo rotate to specific angle (0-180 degrees)
0.25)
*
#make servo rotate from 180 to 0 deg
#make servo rotate from 0 to 180 deg
# Write to servo
# Program start from here
# When 'Ctrl+C' is pressed, the program destroy() will
-
inMin)
/
(inMax
-
# Play song 1
# Change the frequency along the song note
# delay a note for beat * 0.25s
# Wait a second for next song.
# Release resource
(Fortsetzung der vorherigen Seite)
inMin)
+
outMin
(Fortsetzung auf der nächsten Seite)
Kapitel 1. Über das Da Vinci Kit

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis