/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/library/arduino-melody-repeat-example
Library References: https://arduinogetstarted.com/tutorials/arduino-buzzer-library
This example uses a piezo buzzer:
+ play a melody on background
+ repeat the melody when it is ended
+ without using delay() function, this is a non-blocking example
*/
#include "note.h"
//#include <ezBuzzer.h> // ezBuzzer library
#define speaker 12
//const int BUZZER_PIN = 12;
/*************************************************
* Public Constants
*************************************************/
//ezBuzzer buzzer(BUZZER_PIN); // create ezBuzzer object that attaches to a pin;
// notes in the melody:
int noteLength;
void setup() {
Serial.begin(9600);
noteLength = sizeof(noteDurations) / sizeof(int);
}
void loop() {
/*buzzer.loop(); // MUST call the buzzer.loop() function in loop()
if (buzzer.getState() == BUZZER_IDLE) { // if stopped
buzzer.playMelody(melody, noteDurations, noteLength); // playing
}*/
for (int thisNote = 0; thisNote < 112; thisNote++) {
int noteDuration = 750 / noteDurations[thisNote];
tone(speaker, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(speaker);
}
delay(10000);
}