int buzzPin = 2;
int arrayLength;
float interval;
float noteLength = 1000; // 500 = 1/2, 250 = 1/4, etc
float pause1 = 0; // pause after each note
float pause2 = 62; // pause when rest (0)
int i;
int j;
// acceptable range: 5000 (low) - 100 (high)
int const c4 = 1880; // 261.63 Hz
int const db4 = 1775; // 277.18 Hz
int const d4 = 1675; // 293.66 Hz
int const eb4 = 1590; // 311.13 Hz
int const e4 = 1500; // 329.63 Hz
int const f4 = 1410; // 349.23 Hz
int const gb4 = 1340; // 369.99 Hz
int const g4 = 1260;// 392 Hz
int const ab4 = 1190; // 415.30 Hz
int const a4 = 1125; // 440 Hz
int const bb4 = 1065; // 466.16
int const b4 = 1000; // 493.88 Hz
int const c5 = 950; // 523.25 Hz
int const db5 = 895; // 554.37
int const d5 = 840; // 587.33 Hz
int const eb5 = 800; // 622.25
int const e5 = 750; // 659.25 Hz
int const f5 = 705; // 698.46
int const gb5 = 665; // 739.99
int const g5 = 630; // 783.99
int const ab5 = 600; // 830.61
int const a5 = 560; // 880.00 Hz
int const bb5 = 525; // 932.33 Hz
int const b5 = 495; // 987.77 Hz
int const c6 = 465; // 1046.50 Hz
int myNotes [] = {c4, db4, d4, eb4, e4, f4, gb4, g4, ab4, a4, bb4, b4,
c5, db5, d5, eb5, e5, f5, gb5, g5, ab5, a5, bb5, b5,
c6};
//int myNotes [] = {a4, b4, c5, d5, e5, f5, g5, 0};
//int myNotes [] = {a4, a4, a4, g4, g4, g4, f4, f4, f4, f4, f4, f4};
int playNote() {
interval = (noteLength) / (0.002 * myNotes);
for (j = 0; j <= interval; j++) {
digitalWrite(buzzPin, HIGH);
delayMicroseconds(myNotes );
digitalWrite(buzzPin, LOW);
delayMicroseconds(myNotes);
}
}
void setup() {
pinMode(buzzPin, OUTPUT);
arrayLength = sizeof(myNotes) / sizeof(int);
}
void loop() {
for (i = 8; i < 9; i++) {
if (myNotes) {
playNote();
}
else {
delay(pause2);
}
delay(pause1);
}
}