From f78e734a5a4fdb01a80040a15e9177fcc5c4d957 Mon Sep 17 00:00:00 2001 From: Adrian Jaroszewski Date: Thu, 19 Feb 2026 14:52:44 -0500 Subject: [PATCH] Implemented remove point functionality. Decrease a player's score by holding the opposite button down, then pressing the players button. --- src/main.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b8a925a..324755d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,12 +59,11 @@ void setup() { Serial.begin(9600); - while (digitalRead(B1_IN) == 1 && digitalRead(B2_IN) == 1) { + while (digitalRead(B1_IN) == 1 && digitalRead(B2_IN) == 1) {} - - } if (digitalRead(B1_IN) == 0) { while (digitalRead(B1_IN) == 0) {} + serving = 0; displayOut[2] = setServeChar(servingChar, score, serving); setDisplay(score, &matrix, displayOut); @@ -88,47 +87,94 @@ void loop() { while (true) { - while (digitalRead(B1_IN) == 1 && digitalRead(B2_IN) == 1) { + while (digitalRead(B1_IN) == 1 && digitalRead(B2_IN) == 1) {} - - } if (digitalRead(B1_IN) == 0) { while (digitalRead(B1_IN) == 0) { + while (digitalRead(B2_IN) == 0) {} // Only execute remove point on button release. + + if (checkWin(score, 1) == 0) { + removePoint(score, 1); + displayOut[2] = setServeChar(servingChar, score, serving); + game = true; + } + else { + if (checkWin(score, 0) == 0) {} + else { + removePoint(score, 1); + + if (checkWin(score, 0) == 0) { + displayOut[2] = servingChar; + game = false; + } + else {} + } + } + + setDisplay(score, &matrix, displayOut); + delay(500); // to avoid calling twice. + } // Only execute add point on button release. Point removal if other button is pressed during while loop. if (game == true) { scored(score, 0); + if (checkWin(score, 0) == 0) { displayOut[2] = servingChar; game = false; } else { displayOut[2] = setServeChar(servingChar, score, serving); - delay(500); // to avoid calling twice } + setDisplay(score, &matrix, displayOut); + delay(500); // to avoid calling twice } } if (digitalRead(B2_IN) == 0) { while (digitalRead(B2_IN) == 0) { - + + while (digitalRead(B1_IN) == 0) {} // Only execute remove point on button release. + + if (checkWin(score, 0) == 0) { + removePoint(score, 0); + displayOut[2] = setServeChar(servingChar, score, serving); + game = true; + } + else { + if (checkWin(score, 1) == 0) {} + else { + removePoint(score, 0); + + if (checkWin(score, 1) == 0) { + displayOut[2] = servingChar; + game = false; + } + else {} + } + } + + setDisplay(score, &matrix, displayOut); + delay(500); // to avoid calling twice. + } // Only execute add point on button release. Point removal if other button is pressed during while loop. if (game == true) { scored(score, 1); + if (checkWin(score, 1) == 0) { displayOut[2] = servingChar; game = false; } else { displayOut[2] = setServeChar(servingChar, score, serving); - delay(500); // to avoid calling twice } + setDisplay(score, &matrix, displayOut); - } + delay(500); // to avoid calling twice + } } - } - setup(); + } // put function definitions here: @@ -146,6 +192,7 @@ void setDisplay(int* score, MD_Parola* matrix, char* displayOut) { displayOut[i*3] = convertASCII((*(score+i) - (*(score+i)%10)) / 10); displayOut[(i*3)+1] = convertASCII(*(score+i)%10); } + matrix->print(displayOut); }