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

GPIO.setmode(GPIO.BOARD)
GPIO.setup(Buzzer, GPIO.OUT)
global
Buzz
variable to replace GPIO.PWM
Buzz
=
GPIO.PWM(Buzzer, 440)
Buzz.start(50)
cycle
def
loop():
True:
while
print
('\n
for
i
in
range(1, len(song_1)):
Buzz.ChangeFrequency(song_1[i])
time.sleep(beat_1[i]
time.sleep(1)
for next song.
print
('\n\n
for
i
in
range(1, len(song_2)):
Buzz.ChangeFrequency(song_2[i])
time.sleep(beat_2[i]
def
destory():
Buzz.stop()
GPIO.output(Buzzer, 1)
GPIO.cleanup()
if
__name__
==
'__main__':
setup()
try:
loop()
except
KeyboardInterrupt:
will be executed.
destory()
Code Erklärung
CL
=
[0, 131, 147, 165, 175, 196, 211, 248]
CM
=
[0, 262, 294, 330, 350, 393, 441, 495]
major
CH
=
[0, 525, 589, 661, 700, 786, 882, 990]
Dies sind die Frequenzen jeder Note. Die erste 0 ist das Überspringen von CL[0], so dass die Nummer 1-7 dem
CDEFGAB des Tons entspricht.
song_1
=
[
CM[3], CM[5], CM[6], CM[3], CM[2], CM[3], CM[5], CM[6],
CH[1], CM[6], CM[5], CM[1], CM[3], CM[2], CM[2], CM[3],
CM[5], CM[2], CM[3], CM[3], CL[6], CL[6], CL[6], CM[1],
CM[2], CM[3], CM[2], CL[7], CL[6], CM[1], CL[5] ]
Diese Arrays sind die Noten eines Gelieds.
beat_1
=
[
1, 1, 3, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1,
1, 3, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1,
1, 1,
3
Jeder Klangschlage (jede Nummer) repräsentiert den -Schlage oder 0.5s
1.7. 1 Ausgabe
# Set pins' mode is output
# 440 is initial frequency.
Playing song
1...')
0.5)
*
Playing song
2...')
0.5)
*
# Stop the buzzer
# Set Buzzer pin to High
# Program start from here
# When 'Ctrl+C' is pressed, the program destroy()
]
# Numbers GPIOs by physical location
# Assign a global
# Start Buzzer pin with 50% duty
# Play song 1
# Change the frequency along the song note
# delay a note for beat * 0.5s
# Play song 1
# Change the frequency along the song note
# delay a note for beat * 0.5s
# Release resource
# Frequency of Bass tone in C major
# Frequency of Midrange tone in C
# Frequency of Treble tone in C major
SunFounder Da Vinci Kit
(Fortsetzung der vorherigen Seite)
# Wait a second
109

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis