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.
This commit is contained in:
52
src/main.cpp
52
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:
|
||||
|
||||
Reference in New Issue
Block a user