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:
71
src/main.cpp
71
src/main.cpp
@@ -59,12 +59,11 @@ void setup() {
|
|||||||
Serial.begin(9600);
|
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) {
|
if (digitalRead(B1_IN) == 0) {
|
||||||
while (digitalRead(B1_IN) == 0) {}
|
while (digitalRead(B1_IN) == 0) {}
|
||||||
|
|
||||||
serving = 0;
|
serving = 0;
|
||||||
displayOut[2] = setServeChar(servingChar, score, serving);
|
displayOut[2] = setServeChar(servingChar, score, serving);
|
||||||
setDisplay(score, &matrix, displayOut);
|
setDisplay(score, &matrix, displayOut);
|
||||||
@@ -88,47 +87,94 @@ void loop() {
|
|||||||
|
|
||||||
while (true) {
|
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) {
|
if (digitalRead(B1_IN) == 0) {
|
||||||
while (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.
|
} // Only execute add point on button release. Point removal if other button is pressed during while loop.
|
||||||
if (game == true) {
|
if (game == true) {
|
||||||
scored(score, 0);
|
scored(score, 0);
|
||||||
|
|
||||||
if (checkWin(score, 0) == 0) {
|
if (checkWin(score, 0) == 0) {
|
||||||
displayOut[2] = servingChar;
|
displayOut[2] = servingChar;
|
||||||
game = false;
|
game = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
displayOut[2] = setServeChar(servingChar, score, serving);
|
displayOut[2] = setServeChar(servingChar, score, serving);
|
||||||
delay(500); // to avoid calling twice
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setDisplay(score, &matrix, displayOut);
|
setDisplay(score, &matrix, displayOut);
|
||||||
|
delay(500); // to avoid calling twice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (digitalRead(B2_IN) == 0) {
|
if (digitalRead(B2_IN) == 0) {
|
||||||
while (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.
|
} // Only execute add point on button release. Point removal if other button is pressed during while loop.
|
||||||
if (game == true) {
|
if (game == true) {
|
||||||
scored(score, 1);
|
scored(score, 1);
|
||||||
|
|
||||||
if (checkWin(score, 1) == 0) {
|
if (checkWin(score, 1) == 0) {
|
||||||
displayOut[2] = servingChar;
|
displayOut[2] = servingChar;
|
||||||
game = false;
|
game = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
displayOut[2] = setServeChar(servingChar, score, serving);
|
displayOut[2] = setServeChar(servingChar, score, serving);
|
||||||
delay(500); // to avoid calling twice
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setDisplay(score, &matrix, displayOut);
|
setDisplay(score, &matrix, displayOut);
|
||||||
}
|
delay(500); // to avoid calling twice
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// put function definitions here:
|
// 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] = convertASCII((*(score+i) - (*(score+i)%10)) / 10);
|
||||||
displayOut[(i*3)+1] = convertASCII(*(score+i)%10);
|
displayOut[(i*3)+1] = convertASCII(*(score+i)%10);
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix->print(displayOut);
|
matrix->print(displayOut);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user