#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int frecuencias[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 466, 440, 415, 392, 370, 349, 330, 311, 294, 277, 261};
#define PULSADOR 2
#define buzzer 11
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(PULSADOR, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int estadoBoton = digitalRead(PULSADOR);
if (estadoBoton == LOW) {
lcd.display();
lcd.setCursor(0,0);
lcd.print("!Incendio");
lcd.setCursor(4,1);
lcd.print("Detectado¡");
for (int i = 0; i < 23; i++) {
tone(buzzer, frecuencias[i]);
delay(100); // Duración de cada tono
}
noTone(buzzer); // Detiene el sonido
delay(200); // Pausa antes de repetir
} if (estadoBoton == HIGH){
lcd.noDisplay(); // Apaga la pantalla
noTone(buzzer);
}
}