I want to implement a tournament in this air hockey code. How do I modify it?

I am trying to upload from Arduino to Firestore and receive the uploaded data to Android Studio.
What do I need to modify in the following code to receive it in the tournament method (Quarterfinals, Semifinals)?

#include <SoftwareSerial.h>


const byte rxPin = 4;
const byte txPin = 5;

// Set up a new SoftwareSerial object
SoftwareSerial mySerial (rxPin, txPin);

const int buttonPin = 8;                               // Integer to indicated which pin the button is connected to.
int buttonState = 0;                                   // Integer to store data from the button.
int scoreBlue = 0;                                     // Variable to count the score for the blue team.
int scoreRed = 0;                                      // Variable to count the score for the red team.
boolean addScoreBlue = false;                          // Boolean to trigger animation, blue lights and increase in score for the blue team.
boolean addScoreRed = false;                           // Boolean to trigger animation, red lights and increase in score for the red team.
int lineTrackerTriggeredBlue = 0;                      // Variable to display animation and blue light show first and then add the score afterwards.
int lineTrackerTriggeredRed = 0;                       // Variable to display animation and red light show first and then add the score afterwards.
#include <Adafruit_NeoPixel.h>                         // Including Adafruit library to control the NeoPixel.
int lightDelay = 10;                                   // Integer for length of delay in light shows.
const int Pin = 7;                                     // Varible for the pin where the NeoPixel strip is connected to
const int NumberOfPixels = 112;                         // Variable for the number of pixels in the NeoPixel strip
Adafruit_NeoPixel pixels(NumberOfPixels, Pin, NEO_GRB + NEO_KHZ800); //The type of NeoPixel is defined.

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);                                // Initializes the serial monitor and Nextion display.
  attachInterrupt(0, addscoreblue, FALLING);           // Calls the function "addscoreblue" when signal from blue's line tracker is triggered.
  attachInterrupt(1, addscorered, FALLING);            // Calls the function "addscorered" when signal from red's line tracker is triggered.
  pinMode(buttonPin, INPUT_PULLUP);                    // Defining the button as an input.
  pixels.begin();                                      // Initialises the NeoPixel strip.
}

void loop() {
  for (int i = 0; i < 28; i++) {                       // For loop to manage one half of the LED strip.
    pixels.setPixelColor(i, pixels.Color(0, 0, 255));  // Half of the LED's is set to blue.
    pixels.show();
  }                                    // Send the updated pixel colors to the hardware.

  for (int i = 28; i < 84; i++) {          // For loop to manage the other half of the LED strip.
    pixels.setPixelColor(i, pixels.Color(255, 0, 0));  // Sets the other half of LED's to red.
    pixels.show();
  }

  for (int i = 84; i < NumberOfPixels; i++) {                       // For loop to manage one half of the LED strip.
    pixels.setPixelColor(i, pixels.Color(0, 0, 255));  // Half of the LED's is set to blue.
    pixels.show();
  }                                // Send the updated pixel colors to the hardware.

  if (addScoreBlue == true) {                          // If the blue team scores, the following code is executed.
    lineTrackerTriggeredBlue++;
    if (lineTrackerTriggeredBlue == 1) {             // When the puck covers the line tracker, the animation and blue light show are displayed.
      dynamicPixelsBlue();                           // Function to display the blue light show is called.
      mySerial.print("page 1");                        // The page number is send to the Nextion display.
      mySerial.write(0xff);                            // When something is send to a Nextion display, these three lines need to be called.
      mySerial.write(0xff);
      mySerial.write(0xff);
      delay(3000);                                   // Delay to let the animation play for 3 secs.
      scoreBlue = scoreBlue + 1;
      mySerial.print("page 0");                        // The page number is send to the Nextion display to display the scoreboard again.
      mySerial.write(0xff);
      mySerial.write(0xff);
      mySerial.write(0xff);
    }
    if (lineTrackerTriggeredBlue == 2) {             // When is removed from the goal, the score is added in the Nextion display.
      lineTrackerTriggeredBlue = 0;
    }                 // Resets the value, so code above can be repeated if blue team scores again.
    if (lineTrackerTriggeredBlue == 3) {
      lineTrackerTriggeredBlue = 0;
    }
    if (lineTrackerTriggeredBlue == 4) {
    }


  }
  addScoreBlue = false;                                // Sets the boolean to false again, so code above can be repeated if blue team scores again.
  mySerial.print("n0.val=");                             // Defines that the following variable is a number.
  mySerial.print(scoreBlue);                             // The variable of the blue team's score is send to the display.
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);

  if (addScoreRed == true) {                           // If the red team scores, the following code is executed.
    lineTrackerTriggeredRed++;
    if (lineTrackerTriggeredRed == 1) {              // When the puck covers the line tracker, the animation and red light show are displayed.
      dynamicPixelsRed();                            // Function to display the red light show is called.
      mySerial.print("page 1");                        // The page number is send to the Nextion display.
      mySerial.write(0xff);
      mySerial.write(0xff);
      mySerial.write(0xff);
      delay(3000);                                   // Delay to let the animation play for 3 secs.
      scoreRed = scoreRed + 1;

      mySerial.print("page 0");                        // The page number is send to the Nextion display to display the scoreboard again.
      mySerial.write(0xff);
      mySerial.write(0xff);
      mySerial.write(0xff);
    }
    if (lineTrackerTriggeredRed == 2) {              // When is removed from the goal, the score is added in the Nextion display.
      lineTrackerTriggeredRed = 0;
    }                  // Resets the value, so code above can be repeated if red team scores again.
    if (lineTrackerTriggeredRed == 3) {
      lineTrackerTriggeredRed = 0;
    }
    if (lineTrackerTriggeredRed == 4) {
    }
  }
  addScoreRed = false;                                 // Sets the boolean to false again, so code above can be repeated if red team scores again.
  mySerial.print("n1.val=");                             // Defines that the following variable is a number.
  mySerial.print(scoreRed);                              // The variable of the red team's score is send to the display.
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);

  buttonState = digitalRead(buttonPin);                // The Arduino recieves data from the button and sets it as buttonState.
  resetScore();                                        // Calls a function that detect if score needs to be resetted.
  WhoWins();                                           // Calls a function to detect if one of the players won the game.
}

void addscoreblue() {                                  // Function that is called when blue team scores.
  addScoreBlue = true;
}                                // Sets boolean to true, so statement in loop is triggered.

void addscorered() {                                   // Function that is called when red team scores.
  addScoreRed = true;
}                                 // Sets boolean to true, so statement in loop is triggered.

void resetScore() {                                    // Function to reset the score if the button is pressed.
  if (buttonState == LOW) {
    scoreRed = 0;
    scoreBlue = 0;
  }
}



void dynamicPixelsBlue() {                             // Function to make a light show when blue team scores.
  pixels.clear();                                      // Turns off all LED's, so it's ready for the following light pattern.
  for (int i = 0; i < NumberOfPixels; i++) {           // For loop to make wave effect with 10 pixels.
    pixels.setPixelColor(i, pixels.Color(0, 0, 255));  // Pixel i is set to blue.
    pixels.setPixelColor(i - 10, pixels.Color(0, 0, 0)); // The pixel that is 10 behind of pixel i is turned off.
    pixels.show();                                     // Send the updated pixel colors to the hardware.
    delay(lightDelay);
  }                                // Pause before next pass through loop

  for (int i = 56; i > 0; i--) {                       // For loop to make wave effect with 10 pixels but in the other direction than above.
    pixels.setPixelColor(i, pixels.Color(0, 0, 255));  // Pixel i is set to blue.
    pixels.setPixelColor(i + 10, pixels.Color(0, 0, 0)); // The pixel that is 10 infront of pixel i is turned off.
    pixels.show();                                     // Send the updated pixel colors to the hardware.
    delay(lightDelay);
  }                                // Pause before next pass through loop

  for (int i = 0; i < NumberOfPixels; i++) {           // For loop to turn on all pixels.
    pixels.setPixelColor(i, pixels.Color(0, 0, 255));
  } // Sets all pixels to blue.
  pixels.show();                                     // Send the updated pixel colors to the hardware.
  delay(lightDelay + 200);                           // Keeps all LED's on for 210 millisecs.

  for (int i = 0; i < NumberOfPixels; i++) {           // For loop to turn off all pixels.
    pixels.setPixelColor(i, pixels.Color(0, 0, 0));
  }   // Sets all pixels to no color (off).
  pixels.show();                                     // Send the updated pixel colors to the hardware.
  delay(lightDelay + 200);                           // Keeps all LED's off for 210 millisecs.

  for (int i = 0; i < NumberOfPixels; i++) {           // For loop to turn on all pixels.
    pixels.setPixelColor(i, pixels.Color(0, 0, 255));
  } // Sets all pixels to blue.
  pixels.show();                                     // Send the updated pixel colors to the hardware.
  delay(lightDelay + 200);                           // Keeps all LED's on for 210 millisecs.

  for (int i = 0; i < NumberOfPixels; i++) {           // For loop to turn off all pixels.
    pixels.setPixelColor(i, pixels.Color(0, 0, 0));
  }   // Sets all pixels to no color (off).
  pixels.show();                                     // Send the updated pixel colors to the hardware.
  delay(lightDelay + 200);                           // Keeps all LED's off for 210 millisecs.
}

void dynamicPixelsRed() {                              // Exactly same function and structure as the blue light show, but the color is instead red.
  pixels.clear();
  for (int i = 0; i < NumberOfPixels; i++) {
    pixels.setPixelColor(i, pixels.Color(255, 0, 0));
    pixels.setPixelColor(i - 10, pixels.Color(0, 0, 0));
    pixels.show();
    delay(lightDelay);
  }

  for (int i = 56; i > 0; i--) {
    pixels.setPixelColor(i, pixels.Color(255, 0, 0));
    pixels.setPixelColor(i + 10, pixels.Color(0, 0, 0));
    pixels.show();
    delay(lightDelay);
  }


  for (int i = 0; i < NumberOfPixels; i++) {
    pixels.setPixelColor(i, pixels.Color(255, 0, 0));
  }
  pixels.show();
  delay(lightDelay + 200);

  for (int i = 0; i < NumberOfPixels; i++) {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0));
  }
  pixels.show();
  delay(lightDelay + 200);

  for (int i = 0; i < NumberOfPixels; i++) {
    pixels.setPixelColor(i, pixels.Color(255, 0, 0));
  }
  pixels.show();
  delay(lightDelay + 200);

  for (int i = 0; i < NumberOfPixels; i++) {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0));
  }
  pixels.show();
  delay(lightDelay + 200);
}

void WhoWins() {                                       // Function to display winner animation.
  if (scoreBlue == 5) {                                // If blue team scores three goals, the blue winner animation is displayed.

    mySerial.print("page 2");                            // The page number is send to the Nextion display.
    mySerial.write(0xff);
    mySerial.write(0xff);
    mySerial.write(0xff);
    delay(5000);                                       // Delay to let the animation play for 5 secs.
    resetScoreAfterWin();                              // Calls function to reset score.
    mySerial.print("page 0");                            // The page number is send to the Nextion display to display the scoreboard again.
    mySerial.write(0xff);
    mySerial.write(0xff);
    mySerial.write(0xff);
  }

  if (scoreRed == 5) {                                 // If red team scores three goals, the blue winner animation is displayed.

    mySerial.print("page 3");                            // The page number is send to the Nextion display.
    mySerial.write(0xff);
    mySerial.write(0xff);
    mySerial.write(0xff);
    delay(5000);                                       // Delay to let the animation play for 5 secs.
    resetScoreAfterWin();
    mySerial.print("page 0");                            // The page number is send to the Nextion display to display the scoreboard again.
    mySerial.write(0xff);
    mySerial.write(0xff);
    mySerial.write(0xff);
  }
}

void resetScoreAfterWin() {                            // Function to reset score when one of the players won the game.
  scoreRed = 0;
  scoreBlue = 0;
}

Unless you get lucky you need to tell us what you want changed. What does it do and what is it supposed to do. You want to implement a tournament, just exactly does that tell me you need the code to do.

There are 4 matches, and in the first match, who won by getting how many points, and the second match, third match, and fourth match all have to be uploaded to the Firestore every time the match is over. If you upload it like the code above, it will be duplicated when uploaded to Firestore.

what does your current code do? how is it structured?

At the moment of scoring, the LED strip flashes according to the team color.
Whoever scores 5 points first wins and resets when the button is pressed.

https://create.arduino.cc/projecthub/silas_hansen/air-football-cabfb7

here is the original project

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.