From 9eae0f68cee6d659ff455f6ac37ff9836e247552 Mon Sep 17 00:00:00 2001 From: Adrian Jaroszewski Date: Thu, 19 Feb 2026 14:11:58 -0500 Subject: [PATCH] Game variable is now checked on button press rather than on while loop. This is to allow for removing of points (not implemented yet) after a winner is decided. --- src/main.cpp | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0ebd89b..b8a925a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,41 +86,49 @@ void setup() { void loop() { - while (game == true) { + while (true) { while (digitalRead(B1_IN) == 1 && digitalRead(B2_IN) == 1) { } if (digitalRead(B1_IN) == 0) { - while (digitalRead(B1_IN) == 0) {} // Only execute add point on button release - scored(score, 0); - if (checkWin(score, 0) == 0) { - displayOut[2] = servingChar; - game = false; + while (digitalRead(B1_IN) == 0) { + + } // 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); } - else { - displayOut[2] = setServeChar(servingChar, score, serving); - delay(500); // to avoid calling twice - } - setDisplay(score, &matrix, displayOut); } if (digitalRead(B2_IN) == 0) { - while (digitalRead(B2_IN) == 0) {} // Only execute add point on button release - 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); + while (digitalRead(B2_IN) == 0) { + } // 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); + } } } + setup(); } // put function definitions here: