#define BUZZER_PIN 13 // Pin del buzzer
#define BOTON_1 12
#define LED 2
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  // Inicializar el buzzer
  ledcSetup(0, 5000, 8); // Canal 0, frecuencia de 5000 Hz, resolución de 8 bits
  ledcAttachPin(BUZZER_PIN, 0); // Asignar el pin del buzzer al canal 0
  pinMode(BOTON_1, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
}

void loop() {
  int melody[] = {262, 262, 294, 262, 349, 330, 262, 262, 294, 262, 392, 349, 262, 262, 523, 440, 349, 330, 294, 466, 466, 440, 349, 392, 349, 262};
  int noteDurations[] = {4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 2, 4};
  int estadoBoton = digitalRead(BOTON_1);
  
  if (estadoBoton == LOW) {
    digitalWrite(LED, HIGH); // Enciende el LED
    for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
      int noteDuration = 1000 / noteDurations[i];
      ledcWriteTone(0, melody[i]);
      delay(noteDuration);
      ledcWriteTone(0, 0);
      delay(50); // Pausa entre notas
    }
  }
}
$abcdeabcde151015202530354045505560fghijfghij