const int BPM = 60;
const double BarMsLength = 60000/BPM;
struct Note {
int SemitoneDiff;
int NoteType;
double Break;
};
const int NoteCount = 60;
Note CreateNote(int SemitoneDiff, int NoteType, double Break) {
Note RetNote;
RetNote.SemitoneDiff = SemitoneDiff;
RetNote.NoteType = NoteType;
RetNote.Break = Break;
return RetNote;
}
const Note Song[NoteCount] = {
CreateNote(-29,1,0),
CreateNote(-28,2,BarMsLength*4/5),
CreateNote(-29,1,0),
CreateNote(-28,2,BarMsLength*4/5),
CreateNote(-29,1,0),
CreateNote(-28,2,BarMsLength/2),
CreateNote(-29,1,0),
CreateNote(-28,2,BarMsLength/2),
CreateNote(-29,2,0),
CreateNote(-28,4,0),
CreateNote(-29,2,0),
CreateNote(-28,4,0),
CreateNote(-29,4,BarMsLength/4),
CreateNote(-28,4,BarMsLength/4),
CreateNote(-29,4,BarMsLength/4),
CreateNote(-28,4,BarMsLength/4),
CreateNote(-29,4,BarMsLength/4),
CreateNote(-28,4,BarMsLength/4),
CreateNote(-29,4,BarMsLength/4),
CreateNote(-28,4,BarMsLength/4),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-31,4,0),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-31,4,0),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-31,4,0),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-29,8,BarMsLength/8),
CreateNote(-28,8,BarMsLength/8),
CreateNote(-31,4,0),
CreateNote(-28,8,BarMsLength/8)
};
int DelayNote(int noteType) {
int noteDuration = BarMsLength / noteType;
return noteDuration;
}
int NoteToFrequency(int note)
{
return 440 * pow(2.0,note/12.0);
}
void PlayNote(int DistFromA0,int NoteType) {
tone(3,NoteToFrequency(DistFromA0),DelayNote(NoteType));
delay(DelayNote(NoteType));
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(3, OUTPUT);
for (int i=0; i<NoteCount;i++) {
PlayNote(Song[i].SemitoneDiff,Song[i].NoteType);
delay(Song[i].Break);
}
}
void loop() {}