title: Wait for Input before continuing - Arduino Uno
body: <p>I'm making a basic sports game scorer (Squash/Racketball) using an Arduino Uno.</p>
  
  <p>The aim is, 2 buttons, 1 player each has a button that they can increment the score with.<br>
  That's simple enough, however if &amp; when both players happen to get to 10[score] at the same time they need to choose to either go to 13 or 15.</p>
  
  <p>My problem is that it's listening to the last button pressed before calling the <code>scoreDecide()</code> func.</p>
  
  <p>Eg, player1 was on 9(left button), player2 was on 10(right button).</p>
  
  <p>player1 pressed their left button taking them up to 10, <code>scoreDecide()</code> was automatically called as loop recognised it was 10/10[score].</p>
  
  <p>player2 decided to press right button, choosing 15 as score, but it's actually already chosen the left button value as that was the last one pressed before calling the <code>scoreDecide()</code> func, meaning 13 is actually being set as <code>target</code>, and pressing the right button is actually incrementing player2's score.</p>
  
  <p>My code is as follows, I've spent 8 hours so far but I'm a complete novice to Arduino and having no luck.</p>
  
  <pre><code>        // Squash Scorer, by @MrWigster
          // Squash scoring is fairly easy for the most part, however at 10-10 the first player to have reached 10 must decide whether to play until 13 or 15, as the winner must always have a 2 point lead.
          // For this reason we need to include logic to let the players choose what score to play until.
          #include &lt;LiquidCrystal.h&gt;
          LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
          //Setting up Switches, 1 for each player to press.
          const int switchPlayer1 = 7;
          const int switchPlayer2 = 6;
          //Setting up LEDs, 1 representing each player.
          const int led1 = 9;
          const int led2 = 10;
          //Players names
          String player1 = "Bob";
          String player2 = "Alex";
          //Sets up initial values for switches
          int switchStatePlayer1 = 0;
          int switchStatePlayer2 = 0;
          int prevSwitchState1 = 0;
          int prevSwitchState2 = 0;
  
          int p1score = 0;
          int p2score = 0;
          int winner;
          // Initial Target score to get to
          int target = 10;
  
          void setup() {
              lcd.begin(16,2);
              pinMode(switchPlayer1,INPUT);
              pinMode(switchPlayer2,INPUT);
              pinMode(led1,OUTPUT);
              pinMode(led2,OUTPUT);
              lcd.print(player1);
              lcd.print(" Vs ");
              lcd.print(player2);
              lcd.setCursor(0,1);
              lcd.print("SquashScorer 0.1");
          }
  
          void loop() {
              // If LED is still on, turn it off.
              if((digitalRead(led1) == HIGH) || (digitalRead(led2) == HIGH)){
                  delay(200);
              digitalWrite(led1, LOW);
              digitalWrite(led2, LOW);
              }
              // If players scores are the same, and it's at the target score to change
              if ((p1score == p2score) &amp;&amp; (p1score == target)){
                  // Where we call the new target deciding function
                  delay(50); // Trying to give time for button to reset???
                  target = scoreDecide(); // Main code that isn't working
              }
              if ((target == 15) || (target == 13) || (target == 10)) {
                  switchStatePlayer1 = digitalRead(switchPlayer1);
                  if (switchStatePlayer1 != prevSwitchState1){
                      if(switchStatePlayer1 == HIGH){
                          digitalWrite(led1, HIGH);
                          p1score = p1score++;
                          //Deciding if this was winning point
                          if (
                                  (p1score == target +1) || (p2score == target +1)
                                  &amp;&amp; (p1score != p2score)
                              ) {
                              winner = whoWins(player1);
                          }
                          // Writes the new score on the board
                          newScore();
                      }
                  }
                  prevSwitchState1 = switchStatePlayer1;
  
                  switchStatePlayer2 = digitalRead(switchPlayer2);
                  if (switchStatePlayer2 != prevSwitchState2){
                      if(switchStatePlayer2 == HIGH){
                          digitalWrite(led2, HIGH);
                          p2score = p2score++;
                          //Deciding if this was winning point
                          if (
                                  (p1score == target +1) || (p2score == target +1)
                                  &amp;&amp; (p1score != p2score)
                              ) {
                              winner = whoWins(player2);
                          }
                          // Writes the new score on the board
                          newScore();
                      }
                  }
                  prevSwitchState2 = switchStatePlayer2;
              }
          }
  
          // Let the player(s) decide which score to go up to, either 13 or 15.
          int scoreDecide() { // This function doesn't seem to work, its already getting a value before the player gets to choose, based on whatever player last reached TARGET.
              lcd.clear();
              lcd.setCursor(0,0);
              // Give the players the info about which score they can choose
              lcd.print(target + 3);
              lcd.print("    OR    ");
              lcd.print(target + 5);
              switchStatePlayer1 = digitalRead(switchPlayer1);
              if (switchStatePlayer1 != prevSwitchState1){
                  if(switchStatePlayer1 == LOW){
                      target = target + 3;
                      delay(1000);
                      return target;
                  }
              }
              prevSwitchState1 = switchStatePlayer1;
  
              switchStatePlayer2 = digitalRead(switchPlayer2);
              if (switchStatePlayer2 != prevSwitchState2){
                  if(switchStatePlayer2 == LOW){
                      target = target + 5;
                      delay(1000);
                      return target;
                  }
              }
              prevSwitchState2 = switchStatePlayer2;
  
          }
          void newScore(){
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("Bob      Alex");
              lcd.setCursor(0,1);
              lcd.print(p1score);
              lcd.print(" Target:");
              lcd.print(target);
              lcd.print("  ");
              lcd.print(p2score);
          }
          void ledflash(){
              for (int i=0;i&lt;5;i++){
                  digitalWrite(led1, LOW);
                  digitalWrite(led2, HIGH);
                  delay(500);
                  digitalWrite(led1, HIGH);
                  digitalWrite(led2, LOW);
                  delay(500);
              }
              digitalWrite(led1, LOW);
              digitalWrite(led2, LOW);
          }
          int whoWins(String player){
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print(player);
              lcd.setCursor(0,1);
              lcd.print("is the Winner!");
              ledflash();ledflash();
              delay(10000);
              p1score = 0;
              p2score = 0;
              target = 10;
          }
  </code></pre>