#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 = 25;
const int led2Pin = 26;
const int led3Pin = 27;
// Define Button pins
const int button1Pin = 32;
const int button2Pin = 33;
const int button3Pin = 34;
// Variables to store vote counts
int modi = 0;
int kejriwal = 0;
int rahul = 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("Voting Machine");
// Set LED pins as outputs
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
// Set Button pins as inputs with internal pull-up resistors
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
}
void loop() {
// Check if Button1 is pressed
if (digitalRead(button1Pin) == LOW) {
modi++;
lcd.setCursor(0, 1);
lcd.print("Modi 1: ");
lcd.print(modi);
digitalWrite(led1Pin, HIGH);
delay(500);
digitalWrite(led1Pin, LOW);
delay(500);
}
// Check if Button2 is pressed
if (digitalRead(button2Pin) == LOW) {
kejriwal++;
lcd.setCursor(0, 1);
lcd.print("Kejriwal 2: ");
lcd.print(kejriwal);
digitalWrite(led2Pin, HIGH);
delay(500);
digitalWrite(led2Pin, LOW);
delay(500);
}
// Check if Button3 is pressed
if (digitalRead(button3Pin) == LOW) {
rahul++;
lcd.setCursor(0, 1);
lcd.print("Rahul 3: ");
lcd.print(rahul);
digitalWrite(led3Pin, HIGH);
delay(500);
digitalWrite(led3Pin, LOW);
delay(500);
}
// Add a small delay to avoid bouncing issues
delay(100);
}