 
 #include <Wire.h>
 #include <GraphicDisplay.h>
-#include <SM125.h>
+#include <SM125.h> //RFID
+#include <SoundPlayer.h>
 
 #define DISPLAY_ADDRESS  0x51
 #define BUTTONS_CHANGE   43

  allGreen();
  delay(1000);
  clearSquares();
  // Initialize the baseboard peripherals 
  initializeHardwarePeripherals();
  // Show the welcome message
  doWelcome();  
  // Find other player
  rival_id = findPlayer();
}

void loop() {
  delay(200);
  
  // ************************************************************************
  // ******** Player turn ***************************************************
  // ************************************************************************
  for (int i = 0; i < 9; i++){
    previousGreenStatus[i] = greenStatus[i];
  }
  // 1 -Update color status
  //   -Check player move, wait until it happens
  printMsg("Your turn.");
  boolean waitForMove = true;  
  int player_move = 0;
  
  while (waitForMove){
    updateBoardStatus();  
    player_move = checkPlayerMove();
    if (player_move == -1){
      // No move, wait and check again
      delay(30);
    }else if (player_move > -1){
      // Legal move, continue
      waitForMove = false;
    } else if (player_move == -2){
      // Player has moved 2 pieces, illegal move      
      msgAndWait("You moved two pieces! Correct you move.");      
    } else if (player_move == -3){
      // Player has moved the piece into an square already used.     
      msgAndWait("You moved your piece into an already used square! Correct you move.");
    }
  }

  // 2- Send move to server  
  sendMove(player_move);
  
  // 3 -Check victory conditions
  greenVictory = checkWin(greenStatus);
  if (greenVictory){
    printMsg("A winner is you"); //TODO think some proper msgs
    victoryLoop('g');
  }
  
  
  
  // ************************************************************************
  // ******* Rival turn *****************************************************
  // ************************************************************************
  printMsg("Wait for your rival's move.");
  
  // 1- Check rival move, wait until it happens
  waitForMove = true;
  int rival_move = -1;
  while(waitForMove){
    rival_move = getMove();
    // Wait and check again
    if (rival_move < 0){
      delay(100);
    } else{
      waitForMove = false;    
    }
  }  
  // 2- Update color status
  if (rival_move > -1 && rival_move  < 9){
    redStatus[rival_move] = 1;
    squares[rival_move]->setRed();
  }
  
  // 3 -Check victory conditions
  redVictory = checkWin(redStatus);
  if (redVictory){
    printMsg("You lose!"); 
    victoryLoop('r');
  }
}


void setup() {  
  Serial.begin(9600);
  Serial.println("Setup...");
  // 1 - Initialize the tictactoe board
  for (int i = 0; i < 9; i++){
    squares[i] = new Square(8 - i, i + 1, &_sd);
  }
