#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const int team1ButtonPin = 2;
const int team2ButtonPin = 3;
int team1Score = 0; // First team score
int team2Score = 0; // Second team score
char team1[] = "TEAM 1"; // First team name
char team2[] = "TEAM 2"; // Second team name
int teamlen1 = (20 - strlen(team1)) / 2; // For centering teamnames
int teamlen2 = (20 - strlen(team2)) / 2;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(teamlen1, 0);
lcd.print(team1);
lcd.setCursor(10, 1);
lcd.print("-");
lcd.setCursor(teamlen2, 2);
lcd.print(team2);
lcd.setCursor(8, 3);
lcd.print(team1Score);
lcd.print(" : ");
lcd.print(team2Score);
pinMode(team1ButtonPin, INPUT_PULLUP);
pinMode(team2ButtonPin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(team1ButtonPin) == LOW) {
delay(250); // Press this button to increase hometeam score
team1Score++;
updateScoreDisplay();
}
if (digitalRead(team2ButtonPin) == LOW) {
delay(250); // Press this button to increase awayteam score
team2Score++;
updateScoreDisplay();
}
}
void updateScoreDisplay() { // Updates the score when a button was pressed
lcd.setCursor(8, 3);
lcd.print(team1Score);
lcd.print(" : ");
lcd.print(team2Score);
}