Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
Changing behavior when button is pressed early and minor changes
Browse files Browse the repository at this point in the history
Instead of deduction a point when pressing the button too early, the behavior has been changed to reset the timer for the team itself.

Minor changes:
- Documentation is completed
- Properly formatted code
- Small refactoring to cleanup repeated code, as well as making some variables that do not change constant
  • Loading branch information
garrettsummerfi3ld committed Feb 9, 2021
1 parent a035cbf commit ce6691d
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <LiquidCrystal.h>
// Set button values
int redButton = 8, blueButton = 9, resetButton = 10;
const int redButton = 8, blueButton = 9, resetButton = 10;

// Scoring vars
int redTeamCount = 0, blueTeamCount = 0;
Expand Down Expand Up @@ -52,10 +52,7 @@ void setup()
*
* Each time a button is pressed, it will run the desired commands for which
* button is assigned. There are two main buttons that are used for scoring in
* the game. When a scoring button is pressed, it will add a single point to the
* teams score, however there is a penalty if you press the button too early,
* and it will deduct a point from the team. There is a ten second delay on when
* the button will be active to press.
* the game, and a reset button.
*
*/
void loop()
Expand Down Expand Up @@ -88,6 +85,10 @@ void loop()
/**
* @brief Updates Display
*
* Sets the cursor and writes text for each row of the display.
*
* Text written is the physical text for the scoreboard.
*
*/
void displayUpdate()
{
Expand All @@ -101,6 +102,9 @@ void displayUpdate()
/**
* @brief Reset action
*
* Clears scoreboard display, sets all variables to zero, and outputs to the
* user that the scoreboard reset.
*
*/
void resetAction()
{
Expand All @@ -121,69 +125,78 @@ void resetAction()
/**
* @brief Actions per each button press
*
* @param button
* When a scoring button is pressed, it will add a single point to the
* teams score.
*
* Pressing the button when the time last pressed is zero will score a point.
*
* Pressing too early will reset the timer.
*
* The default delay is 10 seconds (10000ms) and is controlled by timerDelay
*
* @param team
*/
void teamAction(int team)
{
if (team == redButton) {
// Red Team Logic
if (team == redButton)
{
Serial.println("[INFO] RED Team button pressed!");
// Give points to a team for pressing the button at the right time
if (currentTime - redTeamLastPressTime >= timerDelay)
{
redTeamCount++;
redTeamLastPressTime = currentTime;
Serial.println("[INFO] RED Team score added!");

delay(150);
}
else if (redTeamLastPressTime == 0)
{
redTeamCount++;
redTeamLastPressTime = currentTime;
Serial.println("[INFO] RED Team score added! TIMER RESET");

delay(150);
Serial.println("[INFO] RED Team score added!");
}
// Deduct points from team for pressing to early
// Reset timer for team for pressing to early
else
{
redTeamCount--;
delay(150);
Serial.println("[INFO] RED Team score lost!");
redTeamLastPressTime = currentTime;
Serial.println("[INFO] RED Team timer reset!");
}
debug();
}

if (team == blueButton) {
// Blue Team Logic
if (team == blueButton)
{
Serial.println("[INFO] BLUE Team button pressed!");
// Give points to a team for pressing the button at the right time
if (currentTime - blueTeamLastPressTime >= timerDelay)
{
blueTeamCount++;
blueTeamLastPressTime = currentTime;
Serial.println("[INFO] BLUE Team score added!");
delay(150);
}
else if (blueTeamLastPressTime == 0)
{
blueTeamCount++;
blueTeamLastPressTime = currentTime;
Serial.println("[INFO] BLUE Team score added!");
delay(150);
}
// Reset timer from team for pressing too early
// Reset timer for team for pressing too early
else
{
blueTeamLastPressTime = currentTime;
Serial.println("[INFO] BLUE Team timer reset!");
delay(150);
}
debug();
}
delay(150);
debug();
}

/**
* @brief Debug prompts
*
* Outputs the current time in milliseconds and the last time each team has
* pressed the button.
*
*/
void debug()
{
Expand Down

0 comments on commit ce6691d

Please sign in to comment.