# Hugo Castro
# Wokwi: https://wokwi.com/projects/479433887790920705
# ISM 3230 - Lab 10
import time
from Lights import *
from Buzzer import *
from TerminalEmulator import *
time.sleep_ms(100)
red = Light(15, 'Red')
green = Light(13, 'Green')
beeper = PassiveBuzzer(14, 'Beeper')
term = TerminalEmulator()
basenotes = {
'Do': 523,
'Re': 587,
'Mi': 659,
'Fa': 698,
'Sol': 784,
'La': 880,
'Ti': 988,
'Rest': 0
}
for note in ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Ti']:
beeper.beep(basenotes[note], duration=250)
time.sleep_ms(250)
reverse = [('Mi', 250, 250), ('Re', 250, 250), ('Do', 250, 250)]
for note, length, pause in reverse:
beeper.beep(basenotes[note], duration=length)
time.sleep_ms(pause)
notechoices = {
'1': 'Do',
'2': 'Re',
'3': 'Mi',
'4': 'Fa',
'5': 'Sol',
'6': 'La',
'7': 'Ti',
'0': 'Rest'
}
song = []
red.on()
while True:
choice = term.input('A:Add, D:Done').strip().upper()
if choice == 'D':
break
elif choice == 'A':
verse = []
while True:
notechoice = term.input('1-7:Note,0:Pause,D:Done').strip().upper()
if notechoice == 'D':
break
elif notechoice in notechoices:
note = notechoices[notechoice]
verse.append((note, 250, 250))
else:
term.print('Invalid note')
song.append(verse)
else:
term.print('Enter A or D')
red.off()
songlength = 0
green.on()
for verse in song:
for note, length, pause in verse:
if note == 'Rest':
time.sleep_ms(length)
else:
beeper.beep(basenotes[note], duration=length)
time.sleep_ms(pause)
songlength += length + pause
green.off()
term.print('Song time: ' + str(songlength / 1000) + ' seconds')