/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: "Buzzer Melody"
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-06-06 17:58:57

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* play https video on buzzer */
/****** SYSTEM REQUIREMENT 2 *****/
	/* play https video youtube on speakers without sd */
	/* card */
/****** END SYSTEM REQUIREMENTS *****/


/****** DEFINITION OF LIBRARIES *****/
#include <ezBuzzer.h>  //https://github.com/ArduinoGetStarted/buzzer

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t mybuzzer_PassiveBuzzer_Signal_PIN_D2 = 2;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool mybuzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float mybuzzer_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
const int BUZZER_PIN = 3;  // Define the pin for the buzzer
ezBuzzer buzzer(BUZZER_PIN);  // Initialize the ezBuzzer object

int melody[] = {
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,
  NOTE_E5,
  NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
  NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,
  NOTE_D5, NOTE_G5
};

int noteDurations[] = {
  8, 8, 4,
  8, 8, 4,
  8, 8, 8, 8,
  2,
  8, 8, 8, 8,
  8, 8, 8, 16, 16,
  8, 8, 8, 8,
  4, 4
};

int noteLength;

void setup(void)
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(mybuzzer_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
  noteLength = sizeof(noteDurations) / sizeof(int);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  buzzer.loop();  // Update the buzzer state

  if (buzzer.getState() == BUZZER_IDLE) {
    buzzer.playMelody(melody, noteDurations, noteLength);  // Play the melody when the buzzer is idle
  }

  updateOutputs();  // Refresh output data
}

void updateOutputs()
{
  digitalWrite(mybuzzer_PassiveBuzzer_Signal_PIN_D2, mybuzzer_PassiveBuzzer_Signal_PIN_D2_rawData);
}

/* END CODE */