#define BOTAO 12
#define LED 13
bool estadoAnterior = HIGH;
bool estadoLED = false;
unsigned long ultimoDebounce = 0;
const unsigned long tempoFiltro = 50;
void setup() {
pinMode(BOTAO, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}
void loop() {
bool leitura = digitalRead(BOTAO);
if (leitura != estadoAnterior) {
ultimoDebounce = millis();
estadoAnterior = leitura;
}
if ((millis() - ultimoDebounce) > tempoFiltro) {
if (leitura == LOW) {
estadoLED = !estadoLED;
digitalWrite(LED, estadoLED);
while (digitalRead(BOTAO) == LOW); // Espera soltar
}
}
}