#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int buttonA = 2;
const int buttonB = 3;
const int resetbutton = 4;
int votesA = 0;
int votesB = 0;
bool lastA = LOW;
bool lastB = LOW;
bool lastreset = LOW;
void setup() {
lcd.begin(16, 2);
lcd.backlight();
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT);
pinMode(resetbutton, INPUT);
lcd.setCursor(0, 0);
lcd.print("Vote System");
delay(1000);
lcd.clear();
updateDisplay();
}
void loop() {
bool readA = digitalRead(buttonA);
bool readB = digitalRead(buttonB);
bool readreset = digitalRead(resetbutton);
if (readA == HIGH && lastA == LOW) {
votesA++;
updateDisplay();
delay(200); // debounce
}
if (readB == HIGH && lastB == LOW) {
votesB++;
updateDisplay();
delay(200); // debounce
}
if (readreset == HIGH && lastreset == LOW) {
votesA = 0;
votesB = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("vote cleared ;)");
delay(1000);
updateDisplay();
delay(200);
}
lastA = readA;
lastB = readB;
lastreset = readreset;
}
void updateDisplay() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("A: ");
lcd.print(votesA);
lcd.setCursor(0, 1);
lcd.print("B: ");
lcd.print(votesB);
}