#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
const int blueButton = 15;
const int redButton = 2;
int redVote = 0;
int blueVote = 0;
int redbuttonState =0;
int blueButtonState =0;
void printVote() {
LCD.setCursor(0, 0);
LCD.print("Red Vote: ");
LCD.print(redVote);
LCD.setCursor(0, 1);
LCD.print("Blue Vote: ");
LCD.print(blueVote);
}
void setup() {
Serial.begin(115200);
pinMode(blueButton, INPUT_PULLUP);
pinMode(redButton, INPUT_PULLUP);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Vote Machine");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("Get Ready");
LCD.setCursor(0, 1);
LCD.print("to Vote");
delay(2000);
}
void loop() {
redbuttonState = digitalRead(redButton);
blueButtonState = digitalRead(blueButton);
if (blueButtonState == LOW) {
delay(50);
if (blueButtonState == LOW) {
blueVote++;
printVote();
}
}
if (redbuttonState == LOW) {
delay(50);
if (redbuttonState == LOW) {
redVote++;
printVote();
}
}
delay(10);
}