Components and supplies
1
I2C IIC 1602 LCD Display Module 16x02 LCD Screen Module for Arduino
3
10kΩ resistor
1
Arduino Uno Rev3
1
10 jumper wires 150mm male
1
Breadboard 100x70
1
Momentary Push Button - Mini
Tools and machines
1
3D printer filament (PLA)
1
3D printer
1
Soldering kit
Apps and platforms
1
Arduino IDE
Project description
Code
Ping Pong Scoreboard
Ping Pong Scoreboard
cpp
1/* 2 * **DuoScore Remix: A Digital Scoreboard with LCD Display for Two-Player Games (I2C Version)** 3 * This is based on the great work of rom4incogn1to 4 * https://projecthub.arduino.cc/rom4incogn1to/duoscore-a-digital-scoreboard-with-lcd-display-for-two-player-games-ae7593 5 * Updates: 6 * Replaced player toggle button with P2 score incrementing. Now there are dedicated buttons for score incrementing. 7 * Removed the need for the dimmer, as it works with an upgraded version of the LCD display that has it built in. 8 * 9 * This project implements a versatile digital scoreboard using an I2C LCD display, designed to track scores for any two-player game. 10 * 11 * This modified version works with an I2C LCD module connected via: 12 * - A5 to SCL 13 * - A4 to SDA 14 * - GND to GND 15 * - 5V to VCC 16 */ 17 18// Include the required libraries for I2C communication and the I2C LCD 19#include <Wire.h> 20#include <LiquidCrystal_I2C.h> 21 22// Initialize the LCD with its I2C address, columns, and rows. 23// Common addresses are 0x27 or 0x3F. If this doesn't work, you may need to find your LCD's specific address. 24LiquidCrystal_I2C lcd(0x27, 16, 2); 25 26// Variables to store the points for both players 27int ptsP1 = 0, ptsP2 = 0; 28 29// NEW: Pins for Hailey's and Dad's score buttons 30const int buttonHailey = 7; // Previously buttonAddPts 31const int buttonDad = 8; // Previously buttonPlayer 32 33// NEW: Last states for Hailey's and Dad's buttons for debouncing 34int lastButtonHaileyState = LOW; 35int lastButtonDadState = LOW; 36 37 38// Pin for the reset button 39const int buttonReset = 9; 40 41// The 'player' variable is no longer needed as each button directly adds to a score. 42// int player = 0; // REMOVED 43 44// Declare the game initialization function 45void gameInit(void); 46 47void setup() { 48 // Initialize the LCD and turn on the backlight 49 lcd.init(); 50 lcd.backlight(); 51 delay(100); 52 53 // Set button pins as inputs 54 pinMode(buttonHailey, INPUT); 55 pinMode(buttonDad, INPUT); 56 pinMode(buttonReset, INPUT); // Make sure reset button is also set as input 57 58 // Display the welcome animation 59 gameInit(); 60} 61 62void loop() { 63 // Use flags to track if display update is needed 64 static int prev_ptsP1 = -1; // Initialize with a value that ensures first update 65 static int prev_ptsP2 = -1; 66 67 bool needsDisplayUpdate = false; 68 69 // --- Hailey's Score Button Logic --- 70 int currentButtonHaileyState = digitalRead(buttonHailey); 71 if (currentButtonHaileyState != lastButtonHaileyState) { 72 if (currentButtonHaileyState == HIGH) { 73 ptsP1 += 1; 74 needsDisplayUpdate = true; // Score changed, update display 75 } 76 lastButtonHaileyState = currentButtonHaileyState; 77 } 78 79 // --- Dad's Score Button Logic --- 80 int currentButtonDadState = digitalRead(buttonDad); 81 if (currentButtonDadState != lastButtonDadState) { 82 if (currentButtonDadState == HIGH) { 83 ptsP2 += 1; 84 needsDisplayUpdate = true; // Score changed, update display 85 } 86 lastButtonDadState = currentButtonDadState; 87 } 88 89 // Reset logic with animation (kept as is) 90 if (digitalRead(buttonReset) == HIGH) { 91 // Reset animation 92 int j = 0; 93 for (int i = 0; i < 16; i++) { 94 lcd.clear(); 95 // Alternate between lines 0 and 1 to display "NEW GAME" 96 if (i % 2 == 0) { 97 j = 0; 98 } else { 99 j = 1; 100 } 101 lcd.setCursor(i, j); 102 lcd.print("NEW GAME"); 103 delay(160); 104 } 105 106 // Reset variables after the animation 107 // The 'player' variable is gone 108 ptsP1 = 0; 109 ptsP2 = 0; 110 111 // Re-run the welcome animation 112 gameInit(); 113 114 // Ensure flags are reset so display updates after reset 115 prev_ptsP1 = -1; 116 prev_ptsP2 = -1; 117 // prev_player = -1; // REMOVED 118 needsDisplayUpdate = true; 119 120 // Wait for the user to release the reset button 121 while (digitalRead(buttonReset) == HIGH) { 122 delay(10); 123 } 124 } 125 126 // --- Optimized Display Update --- 127 // Only update LCD if scores have changed 128 if (needsDisplayUpdate || ptsP1 != prev_ptsP1 || ptsP2 != prev_ptsP2) { 129 // Display Hailey's score 130 lcd.setCursor(0, 0); 131 lcd.print("PLAYER 1: "); // Adjusted string length 132 lcd.print(ptsP1); 133 // Overwrite any extra digits if score decreases (e.g., 100 to 9) 134 if (ptsP1 < 10) lcd.print(" "); // Two spaces for 1-digit number 135 else if (ptsP1 < 100) lcd.print(" "); // One space for 2-digit number 136 137 138 // Display Dad's score 139 lcd.setCursor(0, 1); 140 lcd.print("PLAYER 2: "); // Adjusted string length 141 lcd.print(ptsP2); 142 // Overwrite any extra digits if score decreases 143 if (ptsP2 < 10) lcd.print(" "); // Two spaces for 1-digit number 144 else if (ptsP2 < 100) lcd.print(" "); // One space for 2-digit number 145 146 // The active player indicator is no longer needed 147 // lcd.setCursor(15, 0); // REMOVED 148 // lcd.print(" "); // REMOVED 149 // lcd.setCursor(15, 1); // REMOVED 150 // lcd.print(" "); // REMOVED 151 152 // Update previous states 153 prev_ptsP1 = ptsP1; 154 prev_ptsP2 = ptsP2; 155 } 156 157 // Small delay for button debouncing and to prevent loop from running too fast if nothing is changing 158 delay(10); 159} 160 161// Game initialization function with a loading screen animation 162void gameInit(void) { 163 lcd.clear(); 164 lcd.setCursor(0, 0); // Changed from 3,0 to 0,0 to center "PING PONG SCORES" better 165 lcd.print("PING PONG SCORES"); 166 167 // Loading animation with dots on the bottom line 168 for (int i = 0; i <= 15; i++) { 169 lcd.setCursor(i, 1); 170 lcd.print("."); 171 delay(120); // Delay to adjust the speed of the animation 172 lcd.setCursor(i, 1); 173 lcd.print(" "); 174 } 175 176 // Small pause before clearing the screen 177 delay(200); 178 lcd.clear(); 179}
Downloadable files
Scoreboard case - top cover
Includes hole for inserting the push button.
Ping Pong Scoreboard - TOP.stl
Scoreboard base
Ping Pong Scoreboard - BASE.stl
Comments
Only logged in users can leave comments