#include <math.h>
#define buzz1 9
#define buzz2 10
#define led 13
#define beat 500 // = 60 s / 120 bpm * 1000 ms
#define cnat 16.35
#define csharp 17.32
#define dnat 18.35
#define eb 19.45
#define enat 20.60
#define fnat 21.83
#define fsharp 23.12
#define gnat 24.50
#define gsharp 25.96
#define anat 27.50
#define bb 29.14
#define bnat 30.87
#define oct(note, octave) note * pow(2, octave)
void setup() {
pinMode(led, OUTPUT);
pinMode(buzz1, OUTPUT);
pinMode(buzz2, OUTPUT);
}
void play(double note, int octave, double duration) {
int noteFreq = oct(note, octave);
tone(buzz1, noteFreq, duration * beat);
tone(buzz2, noteFreq, duration * beat); // Si quieres que ambos buzzers suenen con la misma nota
delay(duration * beat);
noTone(buzz1);
noTone(buzz2);
}
void rest(double duration) {
delay(duration * beat);
}
void vibrato(double note, int octave, double duration) {
int noteFreq = oct(note, octave);
for (int i = 0; i < 10; i++) {
tone(buzz1, noteFreq + (i % 2 == 0 ? 2 : -2));
tone(buzz2, noteFreq + (i % 2 == 0 ? 2 : -2));
delay(duration * beat / 10);
}
noTone(buzz1);
noTone(buzz2);
}
void loop() {
// Measure 1
play(dnat, 4, .25);
play(dnat, 4, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
play(cnat, 4, .25);
play(cnat, 4, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
play(bnat, 3, .25);
play(bnat, 3, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
play(bb, 3, .25);
play(bb, 3, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
// 5
play(dnat, 4, .25);
play(dnat, 4, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
play(cnat, 4, .25);
play(cnat, 4, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
play(bnat, 3, .25);
play(bnat, 3, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
play(bb, 3, .25);
play(bb, 3, .25);
play(dnat, 5, .25);
rest(.25);
play(anat, 4, .25);
rest(.5);
play(gsharp, 4, .25);
rest(.25);
play(gnat, 4, .25);
rest(.25);
play(fnat, 4, .5);
play(dnat, 4, .25);
play(fnat, 4, .25);
play(gnat, 4, .25);
// 9
play(dnat, 5, .25);
play(dnat, 5, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(cnat, 5, .25);
play(cnat, 5, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(bnat, 4, .25);
play(bnat, 4, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(bb, 4, .25);
play(bb, 4, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
// Repeat 9
play(dnat, 5, .25);
play(dnat, 5, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(cnat, 5, .25);
play(cnat, 5, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(bnat, 4, .25);
play(bnat, 4, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(bb, 4, .25);
play(bb, 4, .25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
rest(.5);
play(gsharp, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(fnat, 5, .5);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
// 13
play(fnat, 5, .5);
play(fnat, 5, .25);
play(fnat, 5, .25);
rest(.25);
play(fnat, 5, .25);
rest(.15);
play(enat, 5, .10);
play(fnat, 5, .5);
play(dnat, 5, .5);
play(dnat, 5, 1.25);
play(fnat, 5, .5);
play(fnat, 5, .25);
play(fnat, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(gsharp, 5, .5);
play(gnat, 5, .083);
play(gsharp, 5, .083);
play(gnat, 5, .084);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
rest(.5);
play(fnat, 5, .5);
play(fnat, 5, .25);
play(fnat, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(gsharp, 5, .25);
rest(.25);
play(anat, 5, .25);
rest(.25);
play(cnat, 6, .25);
rest(.25);
play(anat, 5, .75);
play(dnat, 6, .25);
rest(.25);
play(dnat, 6, .25);
rest(.25);
play(dnat, 6, .25);
play(anat, 5, .25);
play(dnat, 6, .25);
play(cnat, 6, 1);
vibrato(gnat, 6, 1);
// 17
play(anat, 5, .5);
play(anat, 5, .25);
play(anat, 5, .25);
rest(.25);
play(anat, 5, .25);
rest(.15);
play(gnat, 5, .10);
play(anat, 5, .5);
play(gnat, 5, .5);
play(gnat, 5, 1.25);
play(anat, 5, .5);
play(anat, 5, .25);
play(anat, 5, .25);
rest(.25);
play(anat, 5, .25);
rest(.25);
play(gnat, 5, .25);
rest(.25);
play(anat, 5, .25);
rest(.25);
play(dnat, 6, .25);
rest(.25);
play(anat, 5, .25);
play(gnat, 5, .5);
play(dnat, 6, .5);
play(anat, 5, .5);
play(gnat, 5, .5);
play(fnat, 5, .5);
play(cnat, 6, .5);
play(gnat, 5, .5);
play(fnat, 5, .5);
play(enat, 5, .5);
play(bb, 4, .5);
play(cnat, 5, .25);
play(dnat, 5, .25);
rest(.25);
play(fnat, 5, .25);
rest(.25);
play(cnat, 6, 2.25);
// 21
rest(2);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(gsharp, 5, .125);
play(gnat, 5, .125);
play(fnat, 5, .125);
play(dnat, 5, .125);
play(fnat, 5, .5);
play(gnat, 5, 2.25);
play(gsharp, 5, .5);
play(anat, 5, .25);
play(cnat, 6, .5);
play(anat, 5, .25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(enat, 5, .25);
play(fnat, 5, .5);
play(gnat, 5, .5);
play(anat, 5, .5);
play(cnat, 6, .5);
play(csharp, 6, .5);
play(gsharp, 5, .25);
rest(.25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, 2.25);
// 25
play(fnat, 4, .5);
play(gnat, 4, .5);
play(anat, 4, .5);
play(fnat, 5, .5);
play(enat, 5, 1);
play(dnat, 5, 1);
play(enat, 5, 1);
play(fnat, 5, 1);
play(gnat, 5, 1);
play(enat, 5, 1);
play(anat, 5, 2);
play(anat, 5, .25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fsharp, 5, .25);
play(fnat, 5, .25);
play(enat, 5, .25);
play(eb, 5, .25);
play(dnat, 5, .25);
play(csharp, 5, 2);
play(eb, 5, 2);
// Repeat 21-28
rest(2);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, .25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(gsharp, 5, .125);
play(gnat, 5, .125);
play(fnat, 5, .125);
play(dnat, 5, .125);
play(fnat, 5, .5);
play(gnat, 5, 2.25);
play(gsharp, 5, .5);
play(anat, 5, .25);
play(cnat, 6, .5);
play(anat, 5, .25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fnat, 5, .25);
play(dnat, 5, .25);
play(enat, 5, .25);
play(fnat, 5, .5);
play(gnat, 5, .5);
play(anat, 5, .5);
play(cnat, 6, .5);
play(csharp, 6, .5);
play(gsharp, 5, .25);
rest(.25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fnat, 5, .25);
play(gnat, 5, 2.25);
play(fnat, 4, .5);
play(gnat, 4, .5);
play(anat, 4, .5);
play(fnat, 5, .5);
play(enat, 5, 1);
play(dnat, 5, 1);
play(enat, 5, 1);
play(fnat, 5, 1);
play(gnat, 5, 1);
play(enat, 5, 1);
play(anat, 5, 2);
play(anat, 5, .25);
play(gsharp, 5, .25);
play(gnat, 5, .25);
play(fsharp, 5, .25);
play(fnat, 5, .25);
play(enat, 5, .25);
play(eb, 5, .25);
play(dnat, 5, .25);
play(csharp, 5, 2);
play(eb, 5, 2);
}