Implemented remove point functionality. Decrease a player's score by holding the opposite button down, then pressing the players button.

This commit is contained in:
2026-02-19 14:52:44 -05:00
parent 9eae0f68ce
commit f78e734a5a

View File

@@ -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);
}