code update to avoid loop playback

This commit is contained in:
John Edgar Park 2018-03-23 15:32:47 -07:00
parent b360f3a60c
commit 7f216dff92
2 changed files with 201 additions and 116 deletions

View file

@ -1,3 +1,6 @@
# Plays the 007 theme song
# Gemma M0 with Piezo on D0 and GND
import pulseio
import board
import time
@ -236,30 +239,28 @@ def song_playback(song):
piezo.duty_cycle = 0 # off
time.sleep(0.01)
while True:
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond02)
song_playback(Bond03)
song_playback(Bond02)
song_playback(Bond03)
song_playback(Bond02)
song_playback(Bond04)
song_playback(Bond05)
song_playback(Bond06)
song_playback(Bond07)
song_playback(Bond06)
song_playback(Bond08)
song_playback(Bond09)
song_playback(Bond10)
song_playback(Bond09)
song_playback(Bond10)
song_playback(Bond11)
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond05)
song_playback(Bond12)
time.sleep(5)
# this plays the full song roadmap
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond02)
song_playback(Bond03)
song_playback(Bond02)
song_playback(Bond03)
song_playback(Bond02)
song_playback(Bond04)
song_playback(Bond05)
song_playback(Bond06)
song_playback(Bond07)
song_playback(Bond06)
song_playback(Bond08)
song_playback(Bond09)
song_playback(Bond10)
song_playback(Bond09)
song_playback(Bond10)
song_playback(Bond11)
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond01)
song_playback(Bond05)
song_playback(Bond12)

View file

@ -1,3 +1,6 @@
# Plays the Carmen Sandiego theme song
# Gemma M0 with Piezo on D0 and GND
import pulseio
import board
import time
@ -5,7 +8,7 @@ import time
piezo = pulseio.PWMOut(board.D0, duty_cycle=0, frequency=440,
variable_frequency=True)
tempo = 2
tempo = 1.6
# tempo is length of whole note in seconds, e.g. 1.5
# set up time signature
whole_note = tempo # adjust this to change tempo of everything
@ -19,88 +22,169 @@ eighth_note = whole_note / 8
dotted_eighth_note = eighth_note * 1.5
sixteenth_note = whole_note / 16
carmen01 =[[466, quarter_note],
[466, eighth_note],
[18000, eighth_note],
[18000, sixteenth_note],
[494, eighth_note],
[18000, sixteenth_note],
[494, eighth_note],
[494, eighth_note]]
# set up note values
A2 = 110
As2 = 117 # 's' stands for sharp: A#2
Bb2 = 117
B2 = 123
carmen02 =[[415, quarter_note],
[415, eighth_note],
[18000, eighth_note],
[18000, sixteenth_note],
[415, eighth_note],
[18000, sixteenth_note],
[415, eighth_note],
[494, eighth_note]]
C3 = 131
Cs3 = 139
Db3 = 139
D3 = 147
Ds3 = 156
Eb3 = 156
E3 = 165
F3 = 175
Fs3 = 185
Gb3 = 185
G3 = 196
Gs3 = 208
Ab3 = 208
A3 = 220
As3 = 233
Bb3 = 233
B3 = 247
carmen03 =[[415, quarter_note],
[415, eighth_note],
[18000, eighth_note],
[18000, quarter_note],
[277, eighth_note],
[277, eighth_note]]
C4 = 262
Cs4 = 277
Db4 = 277
D4 = 294
Ds4 = 311
Eb4 = 311
E4 = 330
F4 = 349
Fs4 = 370
Gb4 = 370
G4 = 392
Gs4 = 415
Ab4 = 415
A4 = 440
As4 = 466
Bb4 = 466
B4 = 494
carmen04 =[[466, eighth_note],
[466, sixteenth_note],
[466, eighth_note],
[466, eighth_note],
[494, sixteenth_note],
[494, quarter_note],
[494, eighth_note],
[494, eighth_note]]
C5 = 523
Cs5 = 554
Db5 = 554
D5 = 587
Ds5 = 622
Eb5 = 622
E5 = 659
F5 = 698
Fs5 = 740
Gb5 = 740
G5 = 784
Gs5 = 831
Ab5 = 831
A5 = 880
As5 = 932
Bb5 = 932
B5 = 987
carmen05 =[[415, eighth_note],
[370, eighth_note],
[415, eighth_note],
[370, sixteenth_note],
[554, sixteenth_note],
[554, sixteenth_note],
[466, eighth_note],
[466, sixteenth_note],
[370, eighth_note],
[370, eighth_note]]
# here's another way to express the note pitch, double the previous octave
C6 = C5 * 2
Cs6 = Cs5 * 2
Db6 = Db5 * 2
D6 = D5 * 2
Ds6 = Ds5 * 2
Eb6 = Eb5 * 2
E6 = E5 * 2
F6 = F5 * 2
Fs6 = Fs5 * 2
Gb6 = Gb5 * 2
G6 = G5 * 2
Gs6 = Gs5 * 2
Ab6 = Ab5 * 2
A6 = A5 * 2
As6 = As5 * 2
Bb6 = Bb5 * 2
B6 = B5 * 2
carmen06 =[[415, eighth_note],
[370, eighth_note],
[415, eighth_note],
[370, sixteenth_note],
[415, sixteenth_note],
[415, sixteenth_note],
[415, eighth_note],
[18000, eighth_note],
[18000, eighth_note],
[370, eighth_note]]
rst = 24000 # rest is just a tone out of normal hearing range
carmen07 =[[415, eighth_note],
[370, eighth_note],
[415, eighth_note],
[370, sixteenth_note],
[554, sixteenth_note],
[554, sixteenth_note],
[466, eighth_note],
[466, sixteenth_note],
[415, eighth_note],
[370, eighth_note]]
carmen01 =[[As4, quarter_note],
[As4, eighth_note],
[rst, eighth_note],
[rst, sixteenth_note],
[B4, eighth_note],
[rst, sixteenth_note],
[B4, eighth_note],
[B4, eighth_note]]
carmen08 =[[370, eighth_note],
[18000, eighth_note],
[370, eighth_note],
[370, eighth_note],
[415, eighth_note],
[18000, eighth_note],
[415, eighth_note],
[18000, eighth_note],
[165, eighth_note],
[165, eighth_note],
[165, eighth_note],
[165, sixteenth_note],
[185, eighth_note],
[185, eighth_note],
[18000, quarter_note]]
carmen02 =[[Gs4, quarter_note],
[Gs4, eighth_note],
[rst, eighth_note],
[rst, sixteenth_note],
[Gs4, eighth_note],
[rst, sixteenth_note],
[Gs4, eighth_note],
[B4, eighth_note]]
carmen03 =[[Gs4, quarter_note],
[Gs4, eighth_note],
[rst, eighth_note],
[rst, quarter_note],
[Cs4, eighth_note],
[Cs4, eighth_note]]
carmen04 =[[As4, eighth_note],
[As4, sixteenth_note],
[As4, eighth_note],
[As4, eighth_note],
[B4, sixteenth_note],
[B4, quarter_note],
[B4, eighth_note],
[B4, eighth_note]]
carmen05 =[[Gs4, eighth_note],
[Fs4, eighth_note],
[Gs4, eighth_note],
[Fs4, sixteenth_note],
[Cs5, sixteenth_note],
[Cs5, sixteenth_note],
[As4, eighth_note],
[As4, sixteenth_note],
[Fs4, eighth_note],
[Fs4, eighth_note]]
carmen06 =[[Gs4, eighth_note],
[Fs4, eighth_note],
[Gs4, eighth_note],
[Fs4, sixteenth_note],
[Gs4, sixteenth_note],
[Gs4, sixteenth_note],
[Gs4, eighth_note],
[rst, eighth_note],
[rst, eighth_note],
[Fs4, eighth_note]]
carmen07 =[[Gs4, eighth_note],
[Fs4, eighth_note],
[Gs4, eighth_note],
[Fs4, sixteenth_note],
[Cs5, sixteenth_note],
[Cs5, sixteenth_note],
[As4, eighth_note],
[As4, sixteenth_note],
[Gs4, eighth_note],
[Fs4, eighth_note]]
carmen08 =[[Fs4, eighth_note],
[rst, eighth_note],
[Fs4, eighth_note],
[Fs4, eighth_note],
[Gs4, eighth_note],
[rst, eighth_note],
[Gs4, eighth_note],
[rst, eighth_note],
[E3, eighth_note],
[E3, eighth_note],
[E3, eighth_note],
[E3, sixteenth_note],
[Fs3, eighth_note],
[Fs3, eighth_note],
[rst, quarter_note]]
def song_playback(song):
for n in range(len(song)):
@ -110,16 +194,16 @@ def song_playback(song):
piezo.duty_cycle = 0 # off
time.sleep(0.01)
while True:
song_playback(carmen01)
song_playback(carmen02)
song_playback(carmen01)
song_playback(carmen03)
song_playback(carmen04)
song_playback(carmen05)
song_playback(carmen04)
song_playback(carmen06)
song_playback(carmen04)
song_playback(carmen07)
song_playback(carmen08)
song_playback(carmen08)
song_playback(carmen01)
song_playback(carmen02)
song_playback(carmen01)
song_playback(carmen03)
song_playback(carmen04)
song_playback(carmen05)
song_playback(carmen04)
song_playback(carmen06)
song_playback(carmen04)
song_playback(carmen07)
song_playback(carmen08)
song_playback(carmen08)