/*
Uma urna que coleta votos em 2 opções diferentes, AZUL e VERMELHO, com opção de abstenção (BRANCO).
*/
// PINs
#define BOTAO_VERMELHO 4
#define BOTAO_BRANCO 5
#define BOTAO_AZUL 15
#define VOTO_LIBERADO 13
// Parâmetros
#define PAUSA_APOS_VOTO 2000
// Placar
int votosVermelho = 0;
int votosBranco = 0;
int votosAzul = 0;
void setup() {
Serial.begin(115200);
Serial.println("Iniciando urna...");
// PINs
pinMode(BOTAO_VERMELHO, INPUT_PULLUP);
pinMode(BOTAO_BRANCO, INPUT_PULLUP);
pinMode(BOTAO_AZUL, INPUT_PULLUP);
// LEDs
pinMode(VOTO_LIBERADO, OUTPUT);
Serial.println("Urna iniciada.");
}
void loop() {
digitalWrite(VOTO_LIBERADO, HIGH);
if (digitalRead(BOTAO_VERMELHO) == LOW) votosVermelho++;
else if (digitalRead(BOTAO_AZUL) == LOW) votosAzul++;
else if (digitalRead(BOTAO_BRANCO) == LOW) votosBranco++;
else {
delay(10);
return;
}
digitalWrite(VOTO_LIBERADO, LOW);
exibePlacar();
delay(PAUSA_APOS_VOTO);
}
void exibePlacar() {
Serial.print("Vermelho: "); Serial.print(votosVermelho);
Serial.print(", Branco: "); Serial.print(votosBranco);
Serial.print(", Azul: "); Serial.println(votosAzul);
}