Compare commits
3 Commits
d3ec758ac7
...
f78e734a5a
| Author | SHA1 | Date | |
|---|---|---|---|
| f78e734a5a | |||
| 9eae0f68ce | |||
| 64776b3b43 |
6
LICENSE
6
LICENSE
@@ -208,8 +208,8 @@ If you develop a new program, and you want it to be of the greatest possible use
|
|||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
testt
|
pingpong-counter
|
||||||
Copyright (C) 2025 suseman
|
Copyright (C) 2025 Adrian Jaroszewski
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||||||
|
|
||||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
testt Copyright (C) 2025 suseman
|
pingpong-counter Copyright (C) 2025 Adrian Jaroszewski
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
|||||||
81
src/main.cpp
81
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);
|
||||||
@@ -86,42 +85,97 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
while (game == 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) {} // Only execute add point on button release
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
setDisplay(score, &matrix, displayOut);
|
||||||
delay(500); // to avoid calling twice
|
delay(500); // to avoid calling twice
|
||||||
}
|
}
|
||||||
setDisplay(score, &matrix, displayOut);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (digitalRead(B2_IN) == 0) {
|
if (digitalRead(B2_IN) == 0) {
|
||||||
while (digitalRead(B2_IN) == 0) {} // Only execute add point on button release
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
setDisplay(score, &matrix, displayOut);
|
||||||
delay(500); // to avoid calling twice
|
delay(500); // to avoid calling twice
|
||||||
}
|
}
|
||||||
setDisplay(score, &matrix, displayOut);
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// put function definitions here:
|
// put function definitions here:
|
||||||
|
|
||||||
@@ -138,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