// Kayla Frost
// 300390878
// Arduino Final Project Phase 1 - Test Button for Game Restart
// Nov. 6, 2025
// This snippet tests the function of the button, intended to restart the game (sets all parts back to their initial state).
// bool constants
const int TRUE = 1;
const int FALSE = 0;
const int restartButton = 6; // button is connected to pin 6 on the Arduino
// KF note: reads LOW(0V) when button NOT pressed and HIGH(5V) when button IS pressed
bool gameGo; // TRUE (1) for game going, FALSE (0) for game over
bool gameRestart; // TRUE (1) for game restarting, FALSE (0) for game over
void setup() {
// put your setup code here, to run once:
pinMode(restartButton, INPUT); // define the restart button as an input device
gameGo = TRUE; // game begins
gameRestart = FALSE;
Serial.begin(9600); // to print output messages in the serial monitor
}
void loop() {
// put your main code here, to run repeatedly:
if(gameGo == TRUE) // if game is starting/going
{
delay(2000);
Serial.print("GAME PLAYING! "); //print playing message
// 5 seconds total to mimic the time taken for the game to be played and then lost (54321 countdown)
delay(1000);
Serial.print("5 ");
delay(1000);
Serial.print("4 ");
delay(1000);
Serial.print("3 ");
delay(1000);
Serial.print("2 ");
delay(1000);
Serial.print("1 ");
Serial.print('\n'); //print new line for neatness in serial monitor
Serial.print("YOU LOST, PRESS BUTTON TO RESTART"); // display game over message
Serial.print('\n'); //print new line for neatness in serial monitor
gameGo = FALSE; //since the player has lost, the game is now over
}
// here, the player will press the button to restart the game and keep playing
if(digitalRead(restartButton) == TRUE) //while the restart button is pressed and returns HIGH (TRUE)
{
gameRestart = TRUE; //player wants to restart the game, so game should restart by setting the bool back to TRUE
if(gameRestart == TRUE) //if game is intended to restart
{
Serial.print('\n'); Serial.print("GAME RESTARTING NOW..."); //print restarting message
Serial.print('\n'); Serial.print('\n');//print new line for neatness in serial monitor
gameRestart = FALSE; //set restart bool back to false so it doesn't restart again unless button is pressed again
gameGo = TRUE; // allow the game to go
}
else // if this executes, the gameRestart bool didn't work
{
Serial.print("GAME STILL OVER :( FIX THIS!"); // print error message
Serial.print('\n'); //print new line for neatness in serial monitor
}
}
}