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: