From 70a41b39170494bb3854eb85daa4435930766848 Mon Sep 17 00:00:00 2001 From: Adrian Jaroszewski Date: Thu, 19 Feb 2026 19:30:06 -0500 Subject: [PATCH] Fixed missing curly brace (wouldn't compile) Fixed bug where holding down button decreased score until 0 --- src/main.cpp | 93 +++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 324755d..8da6770 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,10 +55,10 @@ void setup() { matrix.setTextAlignment(PA_CENTER); matrix.setFont(pingpong_font); - + Serial.begin(9600); - + while (digitalRead(B1_IN) == 1 && digitalRead(B2_IN) == 1) {} if (digitalRead(B1_IN) == 0) { @@ -76,44 +76,46 @@ void setup() { displayOut[2] = setServeChar(servingChar, score, serving); setDisplay(score, &matrix, displayOut); delay(500); // to avoid calling twice - - } - - + } + + + } void loop() { while (true) { - + 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 (digitalRead(B2_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 { + if (checkWin(score, 1) == 0) { removePoint(score, 1); - - if (checkWin(score, 0) == 0) { - displayOut[2] = servingChar; - game = false; + displayOut[2] = setServeChar(servingChar, score, serving); + game = true; } - else {} - } - } + else { + if (checkWin(score, 0) == 0) {} + else { + removePoint(score, 1); - setDisplay(score, &matrix, displayOut); - delay(500); // to avoid calling twice. + 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) { @@ -135,28 +137,30 @@ void loop() { if (digitalRead(B2_IN) == 0) { while (digitalRead(B2_IN) == 0) { - while (digitalRead(B1_IN) == 0) {} // Only execute remove point on button release. + if (digitalRead(B1_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 { + if (checkWin(score, 0) == 0) { removePoint(score, 0); - - if (checkWin(score, 1) == 0) { - displayOut[2] = servingChar; - game = false; + displayOut[2] = setServeChar(servingChar, score, serving); + game = true; } - else {} - } - } + else { + if (checkWin(score, 1) == 0) {} + else { + removePoint(score, 0); - setDisplay(score, &matrix, displayOut); - delay(500); // to avoid calling twice. + 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) { @@ -174,7 +178,7 @@ void loop() { delay(500); // to avoid calling twice } } - + } } // put function definitions here: @@ -196,4 +200,3 @@ void setDisplay(int* score, MD_Parola* matrix, char* displayOut) { matrix->print(displayOut); } -