#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD, set the I2C address to 0x27 for a 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define LED pins
const int led1Pin = 33;
const int led2Pin = 25;
const int led3Pin = 26;
// Define Button pins
const int button1Pin = 35;
const int button2Pin = 32;
const int button3Pin = 34;
// Variables to store vote counts
int trump = 0;
int harris = 0;
int moodeng = 0;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize LCD
lcd.init();
lcd.backlight();
// Print a message on the LCD
lcd.setCursor(0, 0);
lcd.print("America E-Voting");
// Set LED pins as outputs
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
// Set Button pins as inputs
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(button1Pin) == LOW) {
trump++;
lcd.setCursor(0, 1);
lcd.print("Trump : ");
lcd.print(trump);
lcd.print(" ");
digitalWrite(led1Pin, HIGH);
delay(500);
digitalWrite(led1Pin, LOW);
delay(500);
}
// Check if Button2 is pressed
if (digitalRead(button2Pin) == LOW) {
harris++;
lcd.setCursor(0, 1);
lcd.print("Harris : ");
lcd.print(harris);
lcd.print(" ");
digitalWrite(led2Pin, HIGH);
delay(500);
digitalWrite(led2Pin, LOW);
delay(500);
}
// Check if Button3 is pressed
if (digitalRead(button3Pin) == LOW) {
moodeng++;
lcd.setCursor(0, 1);
lcd.print("Moodeng : ");
lcd.print(moodeng);
lcd.print(" ");
digitalWrite(led3Pin, HIGH);
delay(500);
digitalWrite(led3Pin, LOW);
delay(500);
}
// Add a small delay to avoid bouncing issues
delay(100);
}