#include <Arduino.h>
const int POT = 26;
const int LED = 15;
const int BUZZER = 14;
const int BOTAO = 16;
bool buzzerSilenciado = false;
bool ultimoEstadoBotao = HIGH;
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(BOTAO, INPUT_PULLUP);
digitalWrite(LED, LOW);
digitalWrite(BUZZER, LOW);
delay(1000);
Serial.println("=================================");
Serial.println("ESTACAO DE ALERTA SONORO");
Serial.println("=================================");
}
void loop() {
int adc = analogRead(POT);
int porcentagem = map(adc, 0, 1023, 0, 100);
if (porcentagem < 0) porcentagem = 0;
if (porcentagem > 100) porcentagem = 100;
bool estadoBotao = digitalRead(BOTAO);
if (ultimoEstadoBotao == HIGH && estadoBotao == LOW) {
buzzerSilenciado = !buzzerSilenciado;
Serial.print("Buzzer ");
Serial.println(buzzerSilenciado ? "SILENCIADO" : "REATIVADO");
delay(200);
}
ultimoEstadoBotao = estadoBotao;
bool ledLigado = false;
if (porcentagem > 70) {
digitalWrite(LED, HIGH);
ledLigado = true;
} else {
digitalWrite(LED, LOW);
ledLigado = false;
buzzerSilenciado = false;
}
bool buzzerLigado = false;
if (porcentagem > 85 && !buzzerSilenciado) {
digitalWrite(BUZZER, HIGH);
buzzerLigado = true;
} else {
digitalWrite(BUZZER, LOW);
buzzerLigado = false;
}
Serial.print("ADC: ");
Serial.print(adc);
Serial.print(" | Nivel: ");
Serial.print(porcentagem);
Serial.print("%");
Serial.print(" | LED: ");
Serial.print(ledLigado ? "ON" : "OFF");
Serial.print(" | Buzzer: ");
Serial.println(buzzerLigado ? "ON" : "OFF");
delay(250);
}