Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 291

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

Buzz
global
GPIO.setmode(GPIO.BCM)
GPIO.setup(ledPin, GPIO.OUT)
GPIO.setup(pirPin, GPIO.IN)
GPIO.setup(buzPin, GPIO.OUT)
Buzz
=
GPIO.PWM(buzPin, 440)
Buzz.start(50)
GPIO.setup(servoPin, GPIO.OUT)
GPIO.output(servoPin, GPIO.LOW)
p
=
GPIO.PWM(servoPin, 50)
p.start(0)
Diese Anweisungen werden verwendet, um die Pins jeder Komponente zu initialisieren.
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
Erstellen Sie eine Funktion von servowrite, um den Winkel in das Servo zu schreiben, der 0-180 ist.
def
doorbell():
for
i
in
range(1,len(song)):
Buzz.ChangeFrequency(song[i])
time.sleep(beat[i]
Erstellen Sie eine Funktion, Türklingel, damit der Summer Musik abspielen kann.
def
closedoor():
GPIO.output(ledPin, GPIO.LOW)
Buzz.ChangeFrequency(1)
for
i
in
range(180, -1, -1):
setAngle(i)
time.sleep(0.001)
Schließen Sie die Tür und schalten Sie die Kontrollleuchte aus.
def
opendoor():
GPIO.output(ledPin, GPIO.LOW)
for
i
in
range(0, 181, 1):
setAngle(i)
time.sleep(0.001)
doorbell()
closedoor()
Die Funktion opendoor () besteht aus mehreren Teilen: Schalten Sie die Anzeigelampe ein, schalten Sie das Servo ein
(um das Öffnen der Tür zu simulieren), spielen Sie die Klingelmusik des Supermarkts und rufen Sie nach dem Spielen
die Funktion Closedoor() auf Musik.
def
loop():
while
True:
if
GPIO.input(pirPin)==GPIO.HIGH:
opendoor()
Wenn RIP erkennt, dass jemand vorbeikommt, ruft es die Funktion opendoor() auf.
1.9. 3 Erweiterung
# Assign a global variable to replace GPIO.PWM
# Numbers GPIOs by physical location
# Set ledPin's mode is output
# Set sensorPin's mode is input
# Set pins' mode is output
# 440 is initial frequency.
# Start Buzzer pin with 50% duty ration
# Set servoPin's mode is output
# Set servoPin to low
# set Frequece to 50Hz
# Duty Cycle = 0
# make the servo rotate to specific angle (0-180 degrees)
# Play song1
# Change the frequency along the song note
0.25)
# delay a note for beat * 0.25s
*
#make servo rotate from 180 to 0 deg
#make servo rotate from 0 to 180 deg
# Write to servo
SunFounder Da Vinci Kit
(Fortsetzung der vorherigen Seite)
287

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis