# CPEMBS1L_isla_LabAct3
# Caesar Cipher: shift <-5
# modules
from machine import I2C, Pin, PWM # since I2C communication would be used, I2C class is imported
from utime import sleep
buzzer = PWM(Pin(15))
# very important
# this module needs to be saved in the Raspberry Pi Pico in order for the LCD I2C to be used
from pico_i2c_lcd import I2cLcd
# creating an I2C object, specifying the data (SDA) and clock (SCL) pins used in the Raspberry Pi Pico
# any SDA and SCL pins in the Raspberry Pi Pico can be used (check documentation for SDA and SCL pins)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
# getting I2C address
I2C_ADDR = i2c.scan()[0]
# creating an LCD object using the I2C address and specifying number of rows and columns in the LCD
# LCD number of rows = 2, number of columns = 16
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
'''
# continuously print and clear "Hello world!" text in the LCD screen while the board has power
while True:
# putstr method allows printing of the text in the LCD screen
# for other methods that can be used, check lcd_api module
lcd.putstr("Hello world!")
sleep(5) # "Hello world!" text would be displayed for 5 secs
lcd.clear()
sleep(1) # clear the text for 1 sec then print the text again
'''
tones = {
"B0": 31,
"C1": 33,
"CS1": 35,
"D1": 37,
"DS1": 39,
"E1": 41,
"F1": 44,
"FS1": 46,
"G1": 49,
"GS1": 52,
"A1": 55,
"AS1": 58,
"B1": 62,
"C2": 65,
"CS2": 69,
"D2": 73,
"DS2": 78,
"E2": 82,
"F2": 87,
"FS2": 93,
"G2": 98,
"GS2": 104,
"A2": 110,
"AS2": 117,
"B2": 123,
"C3": 131,
"CS3": 139,
"D3": 147,
"DS3": 156,
"E3": 165,
"F3": 175,
"FS3": 185,
"G3": 196,
"GS3": 208,
"A3": 220,
"AS3": 233,
"B3": 247,
"C4": 262,
"CS4": 277,
"D4": 294,
"DS4": 311,
"E4": 330,
"F4": 349,
"FS4": 370,
"G4": 392,
"GS4": 415,
"A4": 440,
"AS4": 466,
"B4": 494,
"C5": 523,
"CS5": 554,
"D5": 587,
"DS5": 622,
"E5": 659,
"F5": 698,
"FS5": 740,
"G5": 784,
"GS5": 831,
"A5": 880,
"AS5": 932,
"B5": 988,
"C6": 1047,
"CS6": 1109,
"D6": 1175,
"DS6": 1245,
"E6": 1319,
"F6": 1397,
"FS6": 1480,
"G6": 1568,
"GS6": 1661,
"A6": 1760,
"AS6": 1865,
"B6": 1976,
"C7": 2093,
"CS7": 2217,
"D7": 2349,
"DS7": 2489,
"E7": 2637,
"F7": 2794,
"FS7": 2960,
"G7": 3136,
"GS7": 3322,
"A7": 3520,
"AS7": 3729,
"B7": 3951,
"C8": 4186,
"CS8": 4435,
"D8": 4699,
"DS8": 4978
}
note_durations = {
"whl": 2,
"hlf": 1,
"qtr": 0.5,
"eth": 0.25,
"sxt": 0.125
}
song = [
"F5", "A5", "P", "D5", "F5", "G5", "G5", "F5", "P", "C5", "A4", "G4", # 12
"P", "E4", "P", "GS4", "C5", # 5
"P", "F4", "GS4", "P", "AS4", "P", "AS4", "P", "GS4", # 9 ~ 26
"P", "DS4", "F5", "P", "DS5", "C5", "P", "AS4", "GS4", "F4", "P", "DS4", "P", #13 ~ 26, 33 ~ 39
"C5", "P", "F5", "DS5", "P", "C5", "P", "AS4", "GS4", "AS4", "P", "C5", "DS5", "P", "DS5", "P", "DS4", "P", "F4", "C5", # 20 ~ 39, 47, 53 ~ 59
"P", "C5", "P", "C5", "P", "F5", "DS5", "P", "C5", "P", "AS4", "GS4", "AS4", "P", "C5", "DS5", "P", "DS5", "P", "DS4", "P", "F4", "C5", "P", "C5", # 25 ~ 59, 64, 70, 76 ~ 84
"P", "GS4", "P", "GS4", "P", "DS5", "CS5", "C5", "CS5", "C5", "P", "AS4", # 12 ~ 84, 90~ 96
"P", "DS4", "P", "C5", "DS5", "P", "DS5", "P", "GS4", "P", "F5", "DS5", "P", "C5", "P", "GS4", "P", "AS4", "GS4", "F4", #20 ~ 106, ~ 116
"P", "DS4", "F5", "P", "DS5", "C5", "P", "AS4", "GS4", "F4", "P", "DS4", "P", # 13 ~ 116, 123 ~ 129
"C5", "P", "F5", "DS5", "P", "C5", "P", "AS4", "GS4", "AS4", "P", "C5", "DS5", "P", "DS5", "P", "DS4", "P", "F4", "C5", # 20 ~ 129, 137, 143 ~ 149
"P", "C5", "P", "C5", "P", "F5", "DS5", "P", "C5", "P", "AS4", "GS4", "AS4", "P", "C5", "DS5", "P", "DS5", "P", "DS4", "P", "F4", "C5", "P", "C5", # 25 ~ 149, 154, 160, 166 ~ 174
"P", "GS4", "P", "GS4", "P", "DS5", "CS5", "C5", "CS5", "C5", "P", "AS4", # 12 ~ 184
"P", "DS4", "P", "DS4", "P", "C5", "DS5", "P", "DS5", "P", "GS4", "F5", "DS5", "P", "GS4", "P", "F5", "DS5", "P", "C5", "P", "C5", "AS4" # 23 ~ 207
]
delays = [
"sxt", "hlf", "qtr", "eth", "eth", "sxt", "qtr", "eth", "eth", "eth", "eth", "eth",
"hlf", "eth", "qtr", "sxt", "hlf",
"hlf", "eth", "eth", "sxt", "sxt", "sxt", "qtr", "eth", "hlf",
"hlf", "eth", "eth", "sxt", "eth", "hlf", "eth", "eth", "eth", "eth", "sxt", "hlf", "hlf",
"sxt", "sxt", "eth", "eth", "sxt", "qtr", "sxt", "qtr", "eth", "sxt", "eth", "qtr", "sxt","sxt", "sxt", "qtr", "eth", "sxt", "eth", "hlf",
"qtr", "sxt", "sxt", "sxt", "sxt", "eth", "eth", "sxt", "qtr", "sxt", "eth", "eth", "sxt", "sxt", "qtr", "sxt", "sxt", "eth", "sxt", "qtr", "sxt", "qtr", "sxt", "eth", "eth",
"qtr", "sxt", "sxt", "sxt", "sxt", "qtr", "eth", "qtr", "eth", "eth", "sxt", "qtr",
"qtr", "sxt", "eth", "qtr", "sxt", "sxt", "eth", "sxt", "eth", "sxt", "eth", "eth", "eth", "sxt", "eth", "qtr", "sxt", "sxt", "sxt", "hlf",
"hlf", "eth", "eth", "sxt", "eth", "hlf", "eth", "eth", "eth", "eth", "sxt", "hlf", "hlf",
"sxt", "sxt", "eth", "eth", "sxt", "qtr", "sxt", "qtr", "eth", "sxt", "eth", "qtr", "sxt","sxt", "sxt", "qtr", "eth", "sxt", "eth", "hlf",
"qtr", "sxt", "sxt", "sxt", "sxt", "eth", "eth", "sxt", "qtr", "sxt", "eth", "eth", "sxt", "sxt", "qtr", "sxt", "sxt", "eth", "sxt", "qtr", "sxt", "qtr", "sxt", "eth", "eth",
"qtr", "sxt", "sxt", "sxt", "sxt", "qtr", "eth", "qtr", "eth", "eth", "sxt", "qtr",
"eth", "sxt", "sxt", "sxt", "eth", "qtr", "sxt", "eth", "eth", "eth", "eth", "eth", "qtr", "qtr", "qtr", "sxt", "eth", "qtr", "qtr", "sxt", "sxt", "eth", "qtr"
]
checkctr = [26, 33, 39, 47, 53, 59, 64, 70, 76, 84, 90, 96, 106, 116, 123, 129, 137, 143, 149, 154, 160, 166, 174, 186, 194, 200, -1]
def playtone(frequency):
buzzer.duty_u16(1000)
buzzer.freq(frequency)
def bequiet():
buzzer.duty_u16(0)
def playsong(mysong, mydelays):
print("started")
global checkctr
ctr = 0
for i in range(len(mysong)):
if (mysong[i] == "P"):
bequiet()
else:
playtone(tones[mysong[i]])
#sleep(0.3)
sleep(note_durations[mydelays[i]])
if i == checkctr[ctr]:
print(i)
lyricDisplay(ctr)
ctr+=1
bequiet()
def displayTitle():
lcd.move_to(4,0)
lcd.putstr("Bibingka")
lcd.move_to(3,1)
lcd.putstr("By:Ben&Ben")
sleep(1)
lcd.clear()
lcd.move_to(4,0)
lcd.putstr("*intro*")
ctr1 = 0
def lyricDisplay(ctr):
global ctr1
if ctr == 5 or ctr == 18 or ctr == 21:
ctr1 = 0
if ctr1 == 0:
lcd.clear()
print("nagclear na")
lyrics = [
"Simbang Gabi",
"na naman",
"Tayo gising na,",
"patulog pa lang",
"ang buwan",
"Ang simoy",
"ng hangin,",
"dahan-dahan",
"na humahaplos",
"Sa mukha ng",
"bawat tao",
# ---------------------------
"Bumabagsakbagsak",
"pa ang mata",
# ===========================
"Dahan-dahang",
"kumislap",
"Ang mga ilaw",
"ng tumatandang",
"simbahan",
"Kung san",
"magkasama",
"tayong nagdasal",
"At nakinig sa",
"Misa de Gallo",
# ---------------------------
"Pagdating ng",
"Ama Namin,",
"ang oras huminto"
# ===========================
]
lcd.move_to(0,ctr1)
lcd.putstr(lyrics[ctr])
ctr1+=1
if ctr1 == 2:
ctr1 = 0
print("nag ctr1 = 0")
displayTitle()
playsong(song, delays)