Format Theme Songs
MODIFY
Spy_Theme_Songs/bond.py
Spy_Theme_Songs/bond.py
-# Plays the 007 theme song
-# Gemma M0 with Piezo on D0 and GND
+"""
+Plays the 007 theme song
+Gemma M0 with Piezo on D0 and GND
+"""
-import pulseio
-import board
import time
+import board
+import pulseio
+
piezo = pulseio.PWMOut(board.D0, duty_cycle=0, frequency=440,
variable_frequency=True)
@@ -129,7 +132,6 @@ Bond03=[[E3, eighth_note],
[Fs3, eighth_note],
[Fs3, eighth_note]]
-
Bond04 = [[E3, eighth_note],
[G3, sixteenth_note],
[G3, sixteenth_note],
@@ -231,14 +233,16 @@ Bond12=[[E3, eighth_note],
[rst, quarter_note],
[Fs4, whole_note]]
+
def song_playback(song):
- for n in range(len(song)):
- piezo.frequency = (song[n][0])
+ for note in song:
+ piezo.frequency = (note[0])
piezo.duty_cycle = 65536 // 2 # on 50%
- time.sleep(song[n][1]) # note duration
+ time.sleep(note[1]) # note duration
piezo.duty_cycle = 0 # off
time.sleep(0.01)
+
# this plays the full song roadmap
song_playback(Bond01)
song_playback(Bond01)

MODIFY
Spy_Theme_Songs/carmen.py
Spy_Theme_Songs/carmen.py
-# Plays the Carmen Sandiego theme song
-# Gemma M0 with Piezo on D0 and GND
+"""
+Plays the Carmen Sandiego theme song
+Gemma M0 with Piezo on D0 and GND
+"""
-import pulseio
-import board
import time
+import board
+import pulseio
+
piezo = pulseio.PWMOut(board.D0, duty_cycle=0, frequency=440,
variable_frequency=True)
@@ -186,6 +189,7 @@ carmen08 =[[Fs4, eighth_note],
[Fs3, eighth_note],
[rst, quarter_note]]
+
def song_playback(song):
for n in range(len(song)):
piezo.frequency = (song[n][0])

Format Theme Songs