# Professor Cristiano Teixeira
# Sob Licença Apache 2.0
# Agradescimentos ao Robson Couto: https://github.com/robsoncouto/arduino-songs/tree/master

from machine import Pin, PWM
import time

# Configuração do pino do buzzer
buzzer = PWM(Pin(25), freq=1000, duty=512)

# Frequências das notas musicais (em Hz)
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
REST =   1



# Melodia (sequência de notas)

# Asa branca - Luiz Gonzaga
# Score available at https://musescore.com/user/190926/scores/181370
asabranca = [  G4,8, A4,8, B4,4, D5,4, D5,4, B4,4, 
  C5,4, C5,2, G4,8, A4,8,
  B4,4, D5,4, D5,4, C5,4,

  B4,2, REST,8, G4,8, G4,8, A4,8,
  B4,4, D5,4, REST,8, D5,8, C5,8, B4,8,
  G4,4, C5,4, REST,8, C5,8, B4,8, A4,8,

  A4,4, B4,4, REST,8, B4,8, A4,8, G4,8,
  G4,2, REST,8, G4,8, G4,8, A4,8,
  B4,4, D5,4, REST,8, D5,8, C5,8, B4,8,

  G4,4, C5,4, REST,8, C5,8, B4,8, A4,8,
  A4,4, B4,4, REST,8, B4,8, A4,8, G4,8,
  G4,4, F5,8, D5,8, E5,8, C5,8, D5,8, B4,8,

  C5,8, A4,8, B4,8, G4,8, A4,8, G4,8, E4,8, G4,8,
  G4,4, F5,8, D5,8, E5,8, C5,8, D5,8, B4,8,
  C5,8, A4,8, B4,8, G4,8, A4,8, G4,8, E4,8, G4,8,
  G4,-2, REST,4]
tempoasabranca = 120

# Baby Elephant Walk
# Score available at https://musescore.com/user/7965776/scores/1862611
passodoelefantinho = [
  
  C4,-8, E4,16, G4,8, C5,8, E5,8, D5,8, C5,8, A4,8,
  FS4,8, G4,8, REST,4, REST,2,
  C4,-8, E4,16, G4,8, C5,8, E5,8, D5,8, C5,8, A4,8,
  G4,-2, A4,8, DS4,1,
  
  A4,8,
  E4,8, C4,8, REST,4, REST,2,
  C4,-8, E4,16, G4,8, C5,8, E5,8, D5,8, C5,8, A4,8,
  FS4,8, G4,8, REST,4, REST,4, REST,8, G4,8,
  D5,4, D5,4, B4,8, G4,8, REST,8, G4,8,
   
  C5,4, C5,4, AS4,16, C5,16, AS4,16, G4,16, F4,8, DS4,8,
  FS4,4, FS4,4, F4,16, G4,16, F4,16, DS4,16, C4,8, G4,8,
  AS4,8, C5,8, REST,4, REST,2,
]
tempopassodoelefantinho=132

# Bloody Tears, from Castlevania II
# Arranged by Bobby Lee. THe flute part was used 
# https://musescore.com/user/263171/scores/883296
# B-flat major Bb Eb
bloodytears=[ 
  
  REST, 4, G5, 4,
  A5, 4, AS5, 4,
  A5, 4, F5, 4,
  A5, 4, G5, 4,
  REST, 4, G5, 4,
  A5, 4, AS5, 4,
  C6, 4, AS5, 4,

  A5, 4, G5, 4, 
  REST, 4, G5, 4,
  A5, 4, AS5, 4,
  A5, 4, F5, 4,
  A5, 4, G5, 4,
  D6, 4, REST, 8, C6, 8,
  REST, 4, AS5, 4,

  A5, 4, AS5, 8, C6, 8, 
  F6, 8, REST, 8, REST, 4,
  G5, 16, D5, 16, D6, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,
  A5, 16, D5, 16, AS5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16,
  A5, 16, D5, 16, AS5, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,

  A5, 16, D5, 16, F5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16, 
  G5, 16, D5, 16, D6, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,
  A5, 16, D5, 16, AS5, 16, D5, 16, A5, 16, D5, 16, AS5, 16, D5, 16,
  A5, 16, D5, 16, AS5, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,
  A5, 16, D5, 16, F5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16,

  G5, 16, D5, 16, D6, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16, 
  A5, 16, D5, 16, AS5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16,
  A5, 16, D5, 16, AS5, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,
  A5, 16, D5, 16, F5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16,
  AS5, 16, D5, 16, D6, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,

  A5, 16, D5, 16, AS5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16,
  A5, 16, D5, 16, AS5, 16, D5, 16, C6, 16, D5, 16, AS5, 16, D5, 16,
  A5, 16, D5, 16, F5, 16, D5, 16, A5, 16, D5, 16, G5, 16, D5, 16,
  C6, 16, C6, 16, F6, 16, D6, 8, REST, 16, REST, 8,
  REST, 4, C6, 16, AS5, 16,

  C6, -8,  F6, -8, D6, -4, 
  C6, 8, AS5, 8,
  C6, 8, F6, 16, D6, 8, REST, 16, REST, 8,
  REST, 4, C6, 8, D6, 8,
  DS6, -8, F6, -8,

  D6, -8, REST, 16, DS6, 8, REST, 8, 
  C6, 8, F6, 16, D6, 8, REST, 16, REST, 8,
  REST, 4, C6, 8, AS5, 8,
  C6, -8,  F6, -8, D6, -4,
  C6, 8, AS5, 8,

  C6, 8, F6, 16, D6, 8, REST, 16, REST, 8, 
  REST, 4, C6, 8, D6, 8,
  DS6, -8, F6, -8,
  D5, 8, FS5, 8, F5, 8, A5, 8,
  A5, -8, G5, -4,

  A5, -8, G5, -4, 
  A5, -8, G5, -4,
  AS5, 8, A5, 8, G5, 8, F5, 8,
  A5, -8, G5, -8, D5, 8,
  A5, -8, G5, -8, D5, 8,
  A5, -8, G5, -8, D5, 8,

  AS5, 4, C6, 4, A5, 4, AS5, 4,
  G5,16, D5,16, D6,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, AS5,16, D5,16, A5,16, D5,16, G5,16, D5,16,
  A5,16, D5,16, AS5,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, F5,16, D5,16, A5,16, D5,16, G5,16, D5,16,

  G5,16, D5,16, D6,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, AS5,16, D5,16, A5,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, AS5,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, F5,16, D5,16, A5,16, D5,16, G5,16, D5,16,
  G5,16, D5,16, D6,16, D5,16, C6,16, D5,16, AS5,16, D5,16,

  A5,16, D5,16, AS5,16, D5,16, A5,16, D5,16, G5,16, D5,16,
  A5,16, D5,16, AS5,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, F5,16, D5,16, A5,16, D5,16, G5,16, D5,16,
  AS5,16, D5,16, D6,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5,16, D5,16, AS5,16, D5,16, A5,16, D5,16, G5,16, D5,16,

  A5,16, D5,16, AS5,16, D5,16, C6,16, D5,16, AS5,16, D5,16,
  A5, 16, D5, 16, F5, 16, D5, 16, A5, 8, G5, 32, A5, 32, AS5, 32, C6, 32,
  D6, 16, G5, 16, AS5, 16, G5, 16, C6, 16, G5, 16, D6, 16, G5, 16,
  C6, 16, G5, 16, A5, 16, G5, 16, F6, 16, G5, 16, D6, 16, DS5, 16,
  D6, 4, REST, 4,

  C5, 8, REST, 8, A4, -16, AS4, -16, C5, 16, 
  D6, 16, G4, 16, AS4, 16, G4, 16, C5, 16, G4, 16, D6, 16, G4, 16,
  C6, 16, F4, 16, A4, 16, F4, 16, F5, 16, F4, 16, D6, 16, DS4, 16,
  D6, 16, REST, 8, E4, 16, F4, 16,
  
  
  GS4, 8, REST, 8, AS4, 8, REST, 8,

  DS5, 16, GS4, 16, B4, 16, GS4, 16, CS5, 16, GS4, 16, DS5, 16, GS4, 16, 
  CS5, 16, FS4, 16, AS4, 16, FS4, 16, FS5, 16, FS4, 16, DS5, 16, E5, 16,
  D5, 4, REST, 4,
  CS5, 8, REST, 8, AS4, -16,  B4, -16, CS5, 16,
  DS5, 16, GS4, 16, B4, 16, GS4, 16, CS5, 16, GS4, 16, DS5, 16, GS4, 16,
  
  CS5, 16, FS4, 16, AS4, 16, FS4, 16, FS5, 16, FS4, 16, DS5, 16, E5, 16,
  DS5, 4, REST, 8, DS5, 16,  E5, 16,
  FS5, 16, CS5, 16, E5, 16, CS4, 16, DS5, 16, E5, 16, G5, 16, AS5, 16,
  GS5, 16, DS5, 16, DS6, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,

  AS5, 16, DS5, 16, B5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16, 
  AS5, 16, DS5, 16, B5, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,
  AS5, 16, DS5, 16, FS5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  GS5, 16, DS5, 16, DS6, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,

  AS5, 16, DS5, 16, B5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  AS5, 16, DS5, 16, B5, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,
  AS5, 16, DS5, 16, FS5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  GS5, 16, DS5, 16, DS6, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,

  AS5, 16, DS5, 16, B5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  AS5, 16, DS5, 16, B5, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,
  AS5, 16, DS5, 16, FS5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  GS5, 16, DS5, 16, DS6, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,

  AS5, 16, DS5, 16, B5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  AS5, 16, DS5, 16, B5, 16, DS5, 16, CS6, 16, DS5, 16, B5, 16, DS5, 16,
  AS5, 16, DS5, 16, FS5, 16, DS5, 16, AS5, 16, DS5, 16, GS5, 16, DS5, 16,
  
  CS6, 8, FS6, 16, DS6, 8, REST,16, REST,8, 
  REST,4, CS6, 8, B5, 8,
  CS6,-8, FS6, -8, DS6, -4,
  CS6, 8, B5, 8,
  CS6, 8, FS6, 16, DS6, 8, REST,16, REST,8,
  REST,4, CS6, 8, B5, 8,
  E6, -8, F6, -8,
  
  DS6,-8, REST,16, E6,8, REST,16, REST,16, 
  CS6, 8, FS6, 16, DS6, 8, REST,16, REST,8,
  REST,4, CS6, 8, B5, 8,
  CS6,-8, FS6, -8, DS6, -4,
  CS6, 8, B5, 8,
  
  CS6, 8, FS6, 16, DS6, 8, REST,16, REST,8,
  REST,4, CS5, 8, DS5, 8,
  E5, -8, F5, -8,
  DS5, 8, G5, 8, GS5, 8, AS5, 8,
  AS5, -8, GS5, -8,

  AS5, -8, GS5, -8,
  AS5, -8, GS5, -8,
  B6, 8, AS5, 8, GS5, 8, FS5, 8,
  AS5,-8, GS6, -8, DS5, 8,
  AS5,-8, GS6, -8, DS5, 8,
  AS5,-8, GS6, -8, DS5, 8,

  B5,8, CS6, 8, AS5, 8, B5, 8,
  GS5,8, REST,8, REST, 16
  ]
tempobloodytears=144


# Wiegenlied (Brahms' Lullaby)
# Score available at https://www.flutetunes.com/tunes.php?id=54

nananenem=[

  G4, 4, G4, 4, 
  AS4, -4, G4, 8, G4, 4,
  AS4, 4, REST, 4, G4, 8, AS4, 8,
  DS5, 4, D5, -4, C5, 8,
  C5, 4, AS4, 4, F4, 8, G4, 8,
  GS4, 4, F4, 4, F4, 8, G4, 8,
  GS4, 4, REST, 4, F4, 8, GS4, 8,
  D5, 8, C5, 8, AS4, 4, D5, 4,

  DS5, 4, REST, 4, DS4, 8, DS4, 8, 
  DS5, 2, C5, 8, GS4, 8,
  AS4, 2, G4, 8, DS4, 8,
  GS4, 4, AS4, 4, C5, 4,
  AS4, 2, DS4, 8, DS4, 8,
  DS5, 2, C5, 8, GS4, 8,
  AS4, 2, G4, 8, DS4, 8,
  AS4, 4, G4, 4, DS4, 4,
  DS4, 2
]
temponananenem=76

# Cantina BAnd - Star wars 
# Score available at https://musescore.com/user/6795541/scores/1606876
bandadacantina=[
  B4,-4, E5,-4, B4,-4, E5,-4, 
  B4,8,  E5,-4, B4,8, REST,8,  AS4,8, B4,8, 
  B4,8,  AS4,8, B4,8, A4,8, REST,8, GS4,8, A4,8, G4,8,
  G4,4,  E4,-2, 
  B4,-4, E5,-4, B4,-4, E5,-4, 
  B4,8,  E5,-4, B4,8, REST,8,  AS4,8, B4,8,

  A4,-4, A4,-4, GS4,8, A4,-4,
  D5,8,  C5,-4, B4,-4, A4,-4,
  B4,-4, E5,-4, B4,-4, E5,-4, 
  B4,8,  E5,-4, B4,8, REST,8,  AS4,8, B4,8,
  D5,4, D5,-4, B4,8, A4,-4,
  G4,-4, E4,-2,
  E4, 2, G4,2,
  B4, 2, D5,2,

  F5, -4, E5,-4, AS4,8, AS4,8, B4,4, G4,4, 
]
tempobandadacantina = 140

# Fur Elise - Ludwig van Beethovem
# Score available at https://musescore.com/user/28149610/scores/5281944
furelise = [
    
  E5, 16, DS5, 16, 
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16,
  B4, -8, E4, 16, GS4, 16, B4, 16,
  C5, 8,  REST, 16, E4, 16, E5, 16,  DS5, 16,
  
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16, 
  B4, -8, E4, 16, C5, 16, B4, 16, 
  A4 , 4, REST, 8, 

  
  E5, 16, DS5, 16, 
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16,
  B4, -8, E4, 16, GS4, 16, B4, 16,
  C5, 8,  REST, 16, E4, 16, E5, 16,  DS5, 16,
  
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16, 
  B4, -8, E4, 16, C5, 16, B4, 16, 
  A4, 8, REST, 16, B4, 16, C5, 16, D5, 16, 
  
  E5, -8, G4, 16, F5, 16, E5, 16, 
  D5, -8, F4, 16, E5, 16, D5, 16, 
  
  C5, -8, E4, 16, D5, 16, C5, 16, 
  B4, 8, REST, 16, E4, 16, E5, 16, REST, 16,
  REST, 16, E5, 16, E6, 16, REST, 16, REST, 16, DS5, 16,
  E5, 16, REST, 16, REST, 16, DS5, 16, E5, 16, DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16,
  
  B4, 8, REST, 16, E4, 16, GS4, 16, B4, 16, 
  C5, 8, REST, 16, E4, 16, E5, 16,  DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16,
  B4, 8, REST, 16, E4, 16, C5, 16, B4, 16,
  A4, 8, REST, 16, B4, 16, C5, 16, D5, 16, 
  
  
  E5, -8, G4, 16, F5, 16, E5, 16, 
  D5, -8, F4, 16, E5, 16, D5, 16, 
  
  C5, -8, E4, 16, D5, 16, C5, 16, 
  B4, 8, REST, 16, E4, 16, E5, 16, REST, 16,
  REST, 16, E5, 16, E6, 16, REST, 16, REST, 16, DS5, 16,
  E5, 16, REST, 16, REST, 16, DS5, 16, E5, 16, DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16,
  
  B4, 8, REST, 16, E4, 16, GS4, 16, B4, 16, 
  C5, 8, REST, 16, E4, 16, E5, 16,  DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16,
  B4, 8, REST, 16, E4, 16, C5, 16, B4, 16,
  A4, 8, REST, 16, C5, 16, C5, 16, C5, 16, 

  
  C5 , 4, F5, -16, E5, 32, 
  E5, 8, D5, 8, AS5, -16, A5, 32,
  A5, 16, G5, 16, F5, 16, E5, 16, D5, 16, C5, 16,
  AS4, 8, A4, 8, A4, 32, G4, 32, A4, 32, B4, 32,
  C5 , 4, D5, 16, DS5, 16,
  E5, -8, E5, 16, F5, 16, A4, 16,
  C5 , 4,  D5, -16, B4, 32,
  
  
  C5, 32, G5, 32, G4, 32, G5, 32, A4, 32, G5, 32, B4, 32, G5, 32, C5, 32, G5, 32, D5, 32, G5, 32, 
  E5, 32, G5, 32, C6, 32, B5, 32, A5, 32, G5, 32, F5, 32, E5, 32, D5, 32, G5, 32, F5, 32, D5, 32,
  C5, 32, G5, 32, G4, 32, G5, 32, A4, 32, G5, 32, B4, 32, G5, 32, C5, 32, G5, 32, D5, 32, G5, 32,

  E5, 32, G5, 32, C6, 32, B5, 32, A5, 32, G5, 32, F5, 32, E5, 32, D5, 32, G5, 32, F5, 32, D5, 32, 
  E5, 32, F5, 32, E5, 32, DS5, 32, E5, 32, B4, 32, E5, 32, DS5, 32, E5, 32, B4, 32, E5, 32, DS5, 32,
  E5, -8, B4, 16, E5, 16, DS5, 16,
  E5, -8, B4, 16, E5, 16, REST, 16,

  REST, 16, DS5, 16, E5, 16, REST, 16, REST, 16, DS5, 16, 
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16,
  B4, 8, REST, 16, E4, 16, GS4, 16, B4, 16,
  C5, 8, REST, 16, E4, 16, E5, 16, DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,

  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16, 
  B4, 8, REST, 16, E4, 16, C5, 16, B4, 16,
  A4, 8, REST, 16, B4, 16, C5, 16, D5, 16,
  E5, -8, G4, 16, F5, 16, E5, 16,
  D5, -8, F4, 16, E5, 16, D5, 16,
  C5, -8, E4, 16, D5, 16, C5, 16,
  B4, 8, REST, 16, E4, 16, E5, 16, REST, 16,
  REST, 16, E5, 16, E6, 16, REST, 16, REST, 16, DS5, 16,

  E5, 16, REST, 16, REST, 16, DS5, 16, E5, 16, D5, 16, 
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16,
  B4, 8, REST, 16, E4, 16, GS4, 16, B4, 16,
  C5, 8, REST, 16, E4, 16, E5, 16, DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  
  A4, 8, REST, 16, C4, 16, E4, 16, A4, 16, 
  B4, 8, REST, 16, E4, 16, C5, 16, B4, 16,
  A4, 8, REST, 16, REST, 16, REST, 8, 
  CS5 , -4, 
  D5 , 4, E5, 16, F5, 16,
  F5 , 4, F5, 8, 
  E5 , -4,
  D5 , 4, C5, 16, B4, 16,
  A4 , 4, A4, 8,
  A4, 8, C5, 8, B4, 8,
  A4 , -4,
  CS5 , -4,

  D5 , 4, E5, 16, F5, 16, 
  F5 , 4, F5, 8,
  F5 , -4,
  DS5 , 4, D5, 16, C5, 16,
  AS4 , 4, A4, 8,
  GS4 , 4, G4, 8,
  A4 , -4,
  B4 , 4, REST, 8,
  A3, -32, C4, -32, E4, -32, A4, -32, C5, -32, E5, -32, D5, -32, C5, -32, B4, -32,

  A4, -32, C5, -32, E5, -32, A5, -32, C6, -32, E6, -32, D6, -32, C6, -32, B5, -32, 
  A4, -32, C5, -32, E5, -32, A5, -32, C6, -32, E6, -32, D6, -32, C6, -32, B5, -32,
  AS5, -32, A5, -32, GS5, -32, G5, -32, FS5, -32, F5, -32, E5, -32, DS5, -32, D5, -32,

  CS5, -32, C5, -32, B4, -32, AS4, -32, A4, -32, GS4, -32, G4, -32, FS4, -32, F4, -32, 
  E4, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16,
  B4, -8, E4, 16, GS4, 16, B4, 16,

  C5, 8, REST, 16, E4, 16, E5, 16, DS5, 16, 
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16, 
  A4, -8, C4, 16, E4, 16, A4, 16, 
  B4, -8, E4, 16, C5, 16, B4, 16, 
  A4, -8, REST, -8,
  REST, -8, G4, 16, F5, 16, E5, 16,
  D5 , 4, REST, 8,
  REST, -8, E4, 16, D5, 16, C5, 16,
  
  B4, -8, E4, 16, E5, 8, 
  E5, 8, E6, -8, DS5, 16,
  E5, 16, REST, 16, REST, 16, DS5, 16, E5, 16, DS5, 16,
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16,
  B4, -8, E4, 16, GS4, 16, B4, 16,

  C5, 8, REST, 16, E4, 16, E5, 16, DS5, 16, 
  E5, 16, DS5, 16, E5, 16, B4, 16, D5, 16, C5, 16,
  A4, -8, C4, 16, E4, 16, A4, 16,
  B4, -8, E4, 16, C5, 16, B4, 16,
  A4 , -4,
]
tempofurelise = 80

# Game of Thrones
# Score available at https://musescore.com/user/8407786/scores/2156716
gameofthrones = [
  G4,8, C4,8, DS4,16, F4,16, G4,8, C4,8, DS4,16, F4,16, 
  G4,8, C4,8, DS4,16, F4,16, G4,8, C4,8, DS4,16, F4,16,
  G4,8, C4,8, E4,16, F4,16, G4,8, C4,8, E4,16, F4,16,
  G4,8, C4,8, E4,16, F4,16, G4,8, C4,8, E4,16, F4,16,
  G4,-4, C4,-4,

  DS4,16, F4,16, G4,4, C4,4, DS4,16, F4,16, 
  D4,-1, 
  F4,-4, AS3,-4,
  DS4,16, D4,16, F4,4, AS3,-4,
  DS4,16, D4,16, C4,-1, 


  G4,-4, C4,-4,

  DS4,16, F4,16, G4,4, C4,4, DS4,16, F4,16, 
  D4,-1, 
  F4,-4, AS3,-4,
  DS4,16, D4,16, F4,4, AS3,-4,
  DS4,16, D4,16, C4,-1, 
  G4,-4, C4,-4,
  DS4,16, F4,16, G4,4,  C4,4, DS4,16, F4,16,

  D4,-2,
  F4,-4, AS3,-4,
  D4,-8, DS4,-8, D4,-8, AS3,-8,
  C4,-1,
  C5,-2,
  AS4,-2,
  C4,-2,
  G4,-2,
  DS4,-2,
  DS4,-4, F4,-4, 
  G4,-1,
  
  C5,-2,
  AS4,-2,
  C4,-2,
  G4,-2, 
  DS4,-2,
  DS4,-4, D4,-4,
  C5,8, G4,8, GS4,16, AS4,16, C5,8, G4,8, GS4,16, AS4,16,
  C5,8, G4,8, GS4,16, AS4,16, C5,8, G4,8, GS4,16, AS4,16,
  
  REST,4, GS5,16, AS5,16, C6,8, G5,8, GS5,16, AS5,16,
  C6,8, G5,16, GS5,16, AS5,16, C6,8, G5,8, GS5,16, AS5,16,  
]
tempogameofthrones = 85

# Greensleeves 
# Score available at https://musescore.com/user/168402/scores/1396946
# Alexander Trompoukis
greensleeves = [
  G4,8,
  AS4,4, C5,8, D5,-8, DS5,16, D5,8,
  C5,4, A4,8, F4,-8, G4,16, A4,8,
  AS4,4, G4,8, G4,-8, FS4,16, G4,8,
  A4,4, FS4,8, D4,4, G4,8,
  
  AS4,4, C5,8, D5,-8, DS5,16, D5,8,
  C5,4, A4,8, F4,-8, G4,16, A4,8,
  AS4,-8, A4,16, G4,8, FS4,-8, E4,16, FS4,8, 
  G4,-2,
  F5,2, E5,16, D5,8,

  C5,4, A4,8, F4,-8, G4,16, A4,8,
  AS4,4, G4,8, G4,-8, FS4,16, G4,8,
  A4,4, FS4,8, D4,04,
  F5,2, E5,16, D5,8,
  C5,4, A4,8, F4,-8, G4,16, A4,8,

  AS4,-8, A4,16, G4,8, FS4,-8, E4,16, FS4,8,
  G4,-2,

  

  G4,8,
  AS4,4, C5,8, D5,-8, DS5,16, D5,8,
  C5,4, A4,8, F4,-8, G4,16, A4,8,
  AS4,4, G4,8, G4,-8, FS4,16, G4,8,
  A4,4, FS4,8, D4,4, G4,8,
  
  AS4,4, C5,8, D5,-8, DS5,16, D5,8,
  C5,4, A4,8, F4,-8, G4,16, A4,8,
  AS4,-8, A4,16, G4,8, FS4,-8, E4,16, FS4,8, 
  G4,-2,
  F5,2, E5,16, D5,8,

  C5,4, A4,8, F4,-8, G4,16, A4,8,
  AS4,4, G4,8, G4,-8, FS4,16, G4,8,
  A4,4, FS4,8, D4,04,
  F5,2, E5,16, D5,8,
  C5,4, A4,8, F4,-8, G4,16, A4,8,

  AS4,-8, A4,16, G4,8, FS4,-8, E4,16, FS4,8,
  G4,-2
   
]
tempogreensleeves = 70

# Happy Birthday
# Score available at https://musescore.com/user/8221/scores/26906
parabens = [
  

  C4,4, C4,8, 
  D4,-4, C4,-4, F4,-4,
  E4,-2, C4,4, C4,8, 
  D4,-4, C4,-4, G4,-4,
  F4,-2, C4,4, C4,8,

  C5,-4, A4,-4, F4,-4, 
  E4,-4, D4,-4, AS4,4, AS4,8,
  A4,-4, F4,-4, G4,-4,
  F4,-2,
]
tempoparabens = 140


# Dart Vader theme (Imperial March) - Star wars 
# Score available at https://musescore.com/user/202909/scores/1141521
imperial=[

  
  A4,-4, A4,-4, A4,16, A4,16, A4,16, A4,16, F4,8, REST,8,
  A4,-4, A4,-4, A4,16, A4,16, A4,16, A4,16, F4,8, REST,8,
  A4,4, A4,4, A4,4, F4,-8, C5,16,

  A4,4, F4,-8, C5,16, A4,2,
  E5,4, E5,4, E5,4, F5,-8, C5,16,
  A4,4, F4,-8, C5,16, A4,2,
  
  A5,4, A4,-8, A4,16, A5,4, GS5,-8, G5,16,  
  DS5,16, D5,16, DS5,8, REST,8, A4,8, DS5,4, D5,-8, CS5,16,

  C5,16, B4,16, C5,16, REST,8, F4,8, GS4,4, F4,-8, A4,-16,
  C5,4, A4,-8, C5,16, E5,2,

  A5,4, A4,-8, A4,16, A5,4, GS5,-8, G5,16,  
  DS5,16, D5,16, DS5,8, REST,8, A4,8, DS5,4, D5,-8, CS5,16,

  C5,16, B4,16, C5,16, REST,8, F4,8, GS4,4, F4,-8, A4,-16,
  A4,4, F4,-8, C5,16, A4,2,
]
tempoimperial = 120


# Jigglypuff's Song
# Score available at https://musescore.com/user/28109683/scores/5044153
jigglypuff=[
  D5,-4, A5,8, FS5,8, D5,8,
  E5,-4, FS5,8, G5,4,
  FS5,-4, E5,8, FS5,4,
  D5,-2,
  D5,-4, A5,8, FS5,8, D5,8,
  E5,-4, FS5,8, G5,4,
  FS5,-1,
  D5,-4, A5,8, FS5,8, D5,8,
  E5,-4, FS5,8, G5,4,
  
  FS5,-4, E5,8, FS5,4,
  D5,-2,
  D5,-4, A5,8, FS5,8, D5,8,
  E5,-4, FS5,8, G5,4,
  FS5,-1,
  ]
tempojigglypuff = 85





# Função para tocar a melodia
def tocar_melodia(melodia,tempo):
    notatoda = (60000 * 4) / tempo;
    print("NOTATODA",notatoda)
    divisor = 0
    duracaodanota = 0;
    tamanho=len(melodia)
    for toque in range (0, tamanho, 2):
        divisor=melodia[toque+1]
        if (divisor > 0):
            duracaodanota=(notatoda)/divisor
        elif divisor < 0:
            duracaodanota=(notatoda)/abs(divisor)
            duracaodanota*=1.5
        buzzer.freq(melodia[toque])
        print("NOTA:",melodia[toque])
        time.sleep_ms(int(duracaodanota))
        print("DURAÇAO DA NOTA",duracaodanota)
        buzzer.duty(0)
        time.sleep_ms(50)
        buzzer.duty(512)
    buzzer.duty(0)

# Tocar a melodia
tocar_melodia(gameofthrones,tempogameofthrones)