#define BOTAO 12
int contador = 0;
unsigned long ultimoDebounce = 0;
const unsigned long tempoFiltro = 50;
bool estadoAnterior = HIGH;
void setup() {
pinMode(BOTAO, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
bool leitura = digitalRead(BOTAO);
if (leitura != estadoAnterior) {
ultimoDebounce = millis();
estadoAnterior = leitura;
}
if ((millis() - ultimoDebounce) > tempoFiltro) {
if (leitura == LOW) {
contador++;
if (contador > 9) contador = 0;
Serial.println(contador);
while (digitalRead(BOTAO) == LOW); // Espera soltar
}
}
}