Problem with button playback and buzzer sound playback when a game is integrated into a series of steps

Hello everyone!

I'm trying to integrate a LED Ring Game into my code, everything works perfectly if I only use the Led Ring Game code :

#include "FastLED.h"
#define NUM_LEDS 60
#define DATA_PIN A0

#define BRIGHTNESS 55
CRGB leds[NUM_LEDS];
CRGB sleds[NUM_LEDS];

bool reachedEnd = false;
byte gameState = 0;
//byte ledSpeed = 0;
int period = 1000;
unsigned long time_now = 0;
byte Position = 0;
byte level = 0;

const byte ledSpeed[6] = {50, 40, 30, 20, 14, 7};

//Debounce
bool findRandom = false;
byte spot = 0;

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  pinMode(A3, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Reset");
}

void loop() {
  // put your main code here, to run repeatedly:
  FastLED.setBrightness(BRIGHTNESS );
  if (gameState == 0) {
    fill_rainbow(leds, NUM_LEDS, 0, 20); //2 = longer gradient strip
    
    if (digitalRead(A3) == LOW) {
      Position = 0;
      findRandom = true;
      delay(500);
      for (byte i = 0; i < NUM_LEDS; i++) {
        leds[i].setRGB(0, 0, 0);
        delay(40);
        FastLED.show();
       int thisPitch = map (i, 60, 0, 100, 1500);
       tone(7, thisPitch,120);
      }
      
      gameState = 1;
    }
    FastLED.show();
  }
  if (gameState == 1) {
    period = ledSpeed[0];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot - 1].setRGB(255, 140, 0);
      leds[spot].setRGB(0, 255, 0);
      leds[spot + 1].setRGB(255, 110, 0);
      sleds[0].setRGB(0, 255, 0);
      PlayGame(spot - 1, spot + 1);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      findRandom = false;
      if (Position > spot - 1 && Position < spot + 3) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 2) {
//    period = 320;
    period = ledSpeed[1];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot - 1].setRGB(255, 190, 0);
      leds[spot].setRGB(0, 255, 0);
      leds[spot + 1].setRGB(255, 190, 0);
      sleds[1].setRGB(255, 255, 0);
      PlayGame(spot - 1, spot + 1);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (spot - 1 && Position < spot + 3) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 3) {
    period = ledSpeed[2];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      sleds[2].setRGB(255, 50, 0);
      PlayGame(spot, spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 4) {
    period = ledSpeed[3];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      sleds[3].setRGB(255, 0, 0);
      PlayGame(spot, spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }

  if (gameState == 5) {
    period = ledSpeed[4];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      sleds[4].setRGB(0, 50, 255);
      PlayGame(spot , spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }

  if (gameState == 6) {
    period = ledSpeed[5];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      sleds[5].setRGB(0, 150, 255);
      PlayGame(spot , spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  
  if (gameState == 98) {
    winner();
  }
  if (gameState == 99) {
    loser();
  }
}
void PlayGame(byte bound1, byte bound2) {
  leds[Position].setRGB(255, 0, 0);
  if (Position < bound1 + 1 || Position > bound2 + 1) {
    leds[Position - 1].setRGB(0, 0, 0);
  }
  FastLED.show();
  Position++;
  if (Position >= NUM_LEDS) {
    leds[Position - 1].setRGB(0, 0, 0);
    Position = 0;
  }
}

void winner() {
  for (byte i = 0; i < 3; i++) {
    for (byte j = 0; j < NUM_LEDS; j++) {
      leds[j].setRGB(0, 255, 0);
        tone(7, 1000, 250);
    }
    FastLED.show();
    delay(500);
    clearLEDS();
    FastLED.show();
    delay(500);
  
  }
  findRandom = true;
  Position = 0;

  gameState = level + 1;
  if (gameState > 6) {
    gameState = 0;
  }
}
void loser() {
  for (byte i = 0; i < 3; i++) {
    for (byte j = 0; j < NUM_LEDS; j++) {
      leds[j].setRGB(255, 0, 0);
      tone(7, 200, 250);
    }
    FastLED.show();
    delay(500);
    clearLEDS();
    FastLED.show();
    delay(500);
  }
  gameState = 0;
}
void clearLEDS() {
  for (byte i = 0; i < NUM_LEDS; i++) {
    leds[i].setRGB(0, 0, 0);
  }
}
void winAll(){
  
}

I've integrated it into my code which includes preliminary steps before launching the LED Ring Game, but when the Led Ring game is launched, the buzzer doesn't produce the expected sound and the button (pin A3) doesn't react to pressure. (The LED Ring does light up and the feedback in the console says it has launched).

I don't know why it doesn't work and I can't find a solution to make it work...

here's the complete final code:

#include <SPI.h>
#include <MFRC522.h>
#include "FastLED.h"


// Prototypes de fonction
bool surveillerPins();
void playLEDGame();
void PlayGame(byte bound1, byte bound2);
void winner();
void loser();
void clearLEDS();
void winAll();

#define RST_PIN 5  // Configurable, voir ci-dessus
#define SS_PIN 53  // Configurable, voir votre configuration ci-dessus

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Créer une instance MFRC522


// Définition des pins et variables pour le jeu "LED ring"
#define NUM_LEDS 60
#define DATA_PIN A0
#define BRIGHTNESS 55
CRGB leds[NUM_LEDS];

bool reachedEnd = false;
byte gameState = 0;
int period = 1000;
unsigned long time_now = 0;
byte Position = 0;
byte level = 0;

const byte ledSpeed[6] = {50, 40, 30, 20, 14, 7};

// Débounce
bool findRandom = false;
byte spot = 0;


void setup() {
  Serial.begin(9600);   // Initier la communication série.
  SPI.begin();          // Initier le bus SPI
  mfrc522.PCD_Init();   // Initier le MFRC522
  Serial.println("Présentez votre badge RFID pour le lire...");
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.show();
  pinMode(A3, INPUT_PULLUP);
  tone(7, 1000, 500);
  Serial.println("Reset");
}

void loop() {

  bool buttonPressed = digitalRead(A3) == LOW; 
  // Vérifier si un nouveau badge RFID est présent et prêt à être lu
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }

  // Le badge est présent et prêt à être lu
  // Afficher UID du badge
  Serial.print("UID du badge:");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  // Vérifier si l'UID du badge correspond à un UID autorisé

  byte uidAutorise[] = {0xAC, 0x77, 0xEC, 0x21}; // Remplacez par l'UID de votre badge autorisé
  bool autorise = true;
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] != uidAutorise[i]) {
      autorise = false;
      break;
    }
  }

  if (autorise) {
    Serial.println("Badge autorisé!");
    Serial.println("boitier elec");
     if (surveillerPins()) { // Si surveillerPins retourne true
        playLEDGame(buttonPressed); 
    }
  } else {
    Serial.println("Badge non autorisé.");
  }

  // Assurez-vous de stopper la lecture du badge actuel avant d'en lire un nouveau
  mfrc522.PICC_HaltA();
}

bool surveillerPins() {
  // Configuration des pins comme précédemment...
  pinMode(13, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);  // Ajouter le pin 8 comme entrée
  pinMode(6, OUTPUT);  // Supposons que c'est la LED rouge
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  digitalWrite(6, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);

  while (true) {
    bool etat13 = digitalRead(13) == LOW;
    bool etat4 = digitalRead(4) == LOW;
    bool etat8 = digitalRead(8) == LOW;  // Lire l'état du pin 8

    if (!etat13 && !etat4 && !etat8) {
      // Aucun pin n'est connecté à la masse, y compris le pin 8
      digitalWrite(6, HIGH);  // Allumer la LED rouge
      digitalWrite(2, LOW);   // S'assurer que la pin 2 est éteinte
      digitalWrite(3, LOW);   // S'assurer que la pin 3 est éteinte
    } else if (etat13 && !etat4 && !etat8) {
      // Seul le pin 13 est à la masse, le pin 8 n'est pas à la masse
      digitalWrite(2, HIGH);  // Allumer la pin 2
      digitalWrite(6, LOW);   // Éteindre la LED rouge
      digitalWrite(3, LOW);   // S'assurer que la pin 3 est éteinte
    } else if (etat13 && etat4 && !etat8) {
      // Les pins 13 et 4 sont à la masse, le pin 8 n'est pas à la masse
      digitalWrite(3, HIGH);  // Allumer la pin 3
      digitalWrite(2, LOW);   // Éteindre la pin 2
      // La LED rouge reste éteinte
      Serial.println("Sortie True");
      return true;
      
    } else if (!etat8 && etat4) {
      // Le pin 8 n'est pas à la masse et le pin 4 est connecté
      // La LED rouge doit rester allumée
      digitalWrite(6, HIGH);  // Garder la LED rouge allumée
      // Les autres LEDs restent dans leur état actuel
    } else {
      // Dans tous les autres cas, revenir à l'état de base
      digitalWrite(6, LOW);  // Éteindre la LED rouge
      digitalWrite(2, LOW);  // Éteindre la pin 2
      digitalWrite(3, LOW);  // Éteindre la pin 3
    }

    delay(10);  // Petit délai pour éviter de surcharger le processeur
  }
  return false; // La fonction retournera false si elle sort de la boucle d'une autre manière (actuellement non applicable car la boucle est infinie)
}

void playLEDGame(bool buttonPressed) {
  Serial.println("Début de playLEDGame");
  FastLED.setBrightness(BRIGHTNESS);
  if (gameState == 0) {
    fill_rainbow(leds, NUM_LEDS, 0, 20); //2 = longer gradient strip
  

    if (buttonPressed) {
      Serial.println("Bouton pressé");
      Position = 0;
      findRandom = true;
      delay(500);
      for (byte i = 0; i < NUM_LEDS; i++) {
        leds[i].setRGB(0, 0, 0);
        delay(40);
        FastLED.show();
       int thisPitch = map (i, 60, 0, 100, 1500);
      tone(7, thisPitch,120);
      }
     
      gameState = 1;
    }
    FastLED.show();
  }
  if (gameState == 1) {
    period = ledSpeed[0];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot - 1].setRGB(255, 140, 0);
      leds[spot].setRGB(0, 255, 0);
      leds[spot + 1].setRGB(255, 110, 0);
      // sleds[0].setRGB(0, 255, 0);
      PlayGame(spot - 1, spot + 1);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      findRandom = false;
      if (Position > spot - 1 && Position < spot + 3) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 2) {
  //    period = 320;
    period = ledSpeed[1];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot - 1].setRGB(255, 190, 0);
      leds[spot].setRGB(0, 255, 0);
      leds[spot + 1].setRGB(255, 190, 0);
      // sleds[1].setRGB(255, 255, 0);
      PlayGame(spot - 1, spot + 1);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (spot - 1 && Position < spot + 3) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 3) {
    period = ledSpeed[2];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[2].setRGB(255, 50, 0);
      PlayGame(spot, spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 4) {
    period = ledSpeed[3];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[3].setRGB(255, 0, 0);
      PlayGame(spot, spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }

  if (gameState == 5) {
    period = ledSpeed[4];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[4].setRGB(0, 50, 255);
      PlayGame(spot , spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }

  if (gameState == 6) {
    period = ledSpeed[5];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[5].setRGB(0, 150, 255);
      PlayGame(spot , spot);
    }
    if (digitalRead(A3) == LOW) {
      delay(300);
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  
  if (gameState == 98) {
    winner();
  }
  if (gameState == 99) {
    loser();
  }
}
void PlayGame(byte bound1, byte bound2) {
  leds[Position].setRGB(255, 0, 0);
  if (Position < bound1 + 1 || Position > bound2 + 1) {
    leds[Position - 1].setRGB(0, 0, 0);
  }
  FastLED.show();
  Position++;
  if (Position >= NUM_LEDS) {
    leds[Position - 1].setRGB(0, 0, 0);
    Position = 0;
  }
}

void winner() {
  for (byte i = 0; i < 3; i++) {
    for (byte j = 0; j < NUM_LEDS; j++) {
      leds[j].setRGB(0, 255, 0);
      tone(7, 1000, 250);
    }
    FastLED.show();
    delay(500);
    clearLEDS();
    FastLED.show();
    delay(500);
  
  }
  findRandom = true;
  Position = 0;

  gameState = level + 1;
  if (gameState > 6) {
    gameState = 0;
  }
}
void loser() {
  for (byte i = 0; i < 3; i++) {
    for (byte j = 0; j < NUM_LEDS; j++) {
      leds[j].setRGB(255, 0, 0);
      tone(7, 200, 250);
    }
    FastLED.show();
    delay(500);
    clearLEDS();
    FastLED.show();
    delay(500);
  }
  gameState = 0;
}
void clearLEDS() {
  for (byte i = 0; i < NUM_LEDS; i++) {
    leds[i].setRGB(0, 0, 0);
  }
}
void winAll(){
  
}

Thanks in advance for your suggestions and best regards

This delay (and the other delay() function calls) are causing the button to not respond.

Here is an example of debouncing a button (replaces the "delay()")...
https://docs.arduino.cc/built-in-examples/digital/Debounce/

Hello xfpd,

thanks for your answer.


#include <SPI.h>
#include <MFRC522.h>
#include "FastLED.h"


// Prototypes de fonction
bool surveillerPins();
void playLEDGame();
void PlayGame(byte bound1, byte bound2);
void winner();
void loser();
void clearLEDS();
void winAll();



#define RST_PIN 5  // Configurable, voir ci-dessus
#define SS_PIN 53  // Configurable, voir votre configuration ci-dessus

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Créer une instance MFRC522


// Définition des pins et variables pour le jeu "LED ring"
#define NUM_LEDS 60
#define DATA_PIN A0
#define BRIGHTNESS 55
CRGB leds[NUM_LEDS];

bool reachedEnd = false;
byte gameState = 0;
int period = 1000;
unsigned long time_now = 0;
byte Position = 0;
byte level = 0;

const byte ledSpeed[6] = {50, 40, 30, 20, 14, 7};


// Débounce
bool findRandom = false;
byte spot = 0;


void setup() {
  Serial.begin(9600);   // Initier la communication série.
  SPI.begin();          // Initier le bus SPI
  mfrc522.PCD_Init();   // Initier le MFRC522
  Serial.println("Présentez votre badge RFID pour le lire...");
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.show();
  pinMode(A3, INPUT_PULLUP);
  tone(7, 1000, 500);
  Serial.println("Reset");
}

void loop() {

  bool buttonPressed = digitalRead(A3) == LOW; 
  // Vérifier si un nouveau badge RFID est présent et prêt à être lu
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    millis();
    return;
  }

  // Le badge est présent et prêt à être lu
  // Afficher UID du badge
  Serial.print("UID du badge:");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  // Vérifier si l'UID du badge correspond à un UID autorisé

  byte uidAutorise[] = {0xAC, 0x77, 0xEC, 0x21}; // Remplacez par l'UID de votre badge autorisé
  bool autorise = true;
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] != uidAutorise[i]) {
      autorise = false;
      break;
    }
  }

  if (autorise) {
    Serial.println("Badge autorisé!");
    Serial.println("boitier elec");
     if (surveillerPins()) { // Si surveillerPins retourne true
        playLEDGame(buttonPressed); 
    }
  } else {
    Serial.println("Badge non autorisé.");
  }

  // Assurez-vous de stopper la lecture du badge actuel avant d'en lire un nouveau
  mfrc522.PICC_HaltA();
}

bool surveillerPins() {
  // Configuration des pins comme précédemment...
  pinMode(13, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);  // Ajouter le pin 8 comme entrée
  pinMode(6, OUTPUT);  // Supposons que c'est la LED rouge
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  digitalWrite(6, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);

  while (true) {
    bool etat13 = digitalRead(13) == LOW;
    bool etat4 = digitalRead(4) == LOW;
    bool etat8 = digitalRead(8) == LOW;  // Lire l'état du pin 8

    if (!etat13 && !etat4 && !etat8) {
      // Aucun pin n'est connecté à la masse, y compris le pin 8
      digitalWrite(6, HIGH);  // Allumer la LED rouge
      digitalWrite(2, LOW);   // S'assurer que la pin 2 est éteinte
      digitalWrite(3, LOW);   // S'assurer que la pin 3 est éteinte
    } else if (etat13 && !etat4 && !etat8) {
      // Seul le pin 13 est à la masse, le pin 8 n'est pas à la masse
      digitalWrite(2, HIGH);  // Allumer la pin 2
      digitalWrite(6, LOW);   // Éteindre la LED rouge
      digitalWrite(3, LOW);   // S'assurer que la pin 3 est éteinte
    } else if (etat13 && etat4 && !etat8) {
      // Les pins 13 et 4 sont à la masse, le pin 8 n'est pas à la masse
      digitalWrite(3, HIGH);  // Allumer la pin 3
      digitalWrite(2, LOW);   // Éteindre la pin 2
      // La LED rouge reste éteinte
      Serial.println("Sortie True");
      return true;
      
    } else if (!etat8 && etat4) {
      // Le pin 8 n'est pas à la masse et le pin 4 est connecté
      // La LED rouge doit rester allumée
      digitalWrite(6, HIGH);  // Garder la LED rouge allumée
      // Les autres LEDs restent dans leur état actuel
    } else {
      // Dans tous les autres cas, revenir à l'état de base
      digitalWrite(6, LOW);  // Éteindre la LED rouge
      digitalWrite(2, LOW);  // Éteindre la pin 2
      digitalWrite(3, LOW);  // Éteindre la pin 3
    }

    millis();  // Petit délai pour éviter de surcharger le processeur
  }
  return false; // La fonction retournera false si elle sort de la boucle d'une autre manière (actuellement non applicable car la boucle est infinie)
}

void playLEDGame(bool buttonPressed) {
  Serial.println("Début de playLEDGame");
  FastLED.setBrightness(BRIGHTNESS);
  if (gameState == 0) {
    fill_rainbow(leds, NUM_LEDS, 0, 20); //2 = longer gradient strip
  

    if (buttonPressed) {
      Serial.println("Bouton pressé");
      Position = 0;
      findRandom = true;
      millis();
      for (byte i = 0; i < NUM_LEDS; i++) {
        leds[i].setRGB(0, 0, 0);
        millis();
        FastLED.show();
       int thisPitch = map (i, 60, 0, 100, 1500);
      tone(7, thisPitch,120);
      }
     
      gameState = 1;
    }
    FastLED.show();
  }
  if (gameState == 1) {
    period = ledSpeed[0];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot - 1].setRGB(255, 140, 0);
      leds[spot].setRGB(0, 255, 0);
      leds[spot + 1].setRGB(255, 110, 0);
      // sleds[0].setRGB(0, 255, 0);
      PlayGame(spot - 1, spot + 1);
    }
    if (digitalRead(A3) == LOW) {
      millis();
      findRandom = false;
      if (Position > spot - 1 && Position < spot + 3) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 2) {
  //    period = 320;
    period = ledSpeed[1];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot - 1].setRGB(255, 190, 0);
      leds[spot].setRGB(0, 255, 0);
      leds[spot + 1].setRGB(255, 190, 0);
      // sleds[1].setRGB(255, 255, 0);
      PlayGame(spot - 1, spot + 1);
    }
    if (digitalRead(A3) == LOW) {
      millis();
      if (spot - 1 && Position < spot + 3) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 3) {
    period = ledSpeed[2];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[2].setRGB(255, 50, 0);
      PlayGame(spot, spot);
    }
    if (digitalRead(A3) == LOW) {
      millis();
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  if (gameState == 4) {
    period = ledSpeed[3];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[3].setRGB(255, 0, 0);
      PlayGame(spot, spot);
    }
    if (digitalRead(A3) == LOW) {
      millis();
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }

  if (gameState == 5) {
    period = ledSpeed[4];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[4].setRGB(0, 50, 255);
      PlayGame(spot , spot);
    }
    if (digitalRead(A3) == LOW) {
      millis();
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }

  if (gameState == 6) {
    period = ledSpeed[5];
    if (millis() > time_now + period) {
      time_now = millis();
      if (findRandom) {
        spot = random(56) + 3;
        findRandom = false;
      }
      leds[spot].setRGB(0, 255, 0);
      // sleds[5].setRGB(0, 150, 255);
      PlayGame(spot , spot);
    }
    if (digitalRead(A3) == LOW) {
      millis();
      if (Position == spot+1) {
        level = gameState;
        gameState = 98;
      } else {
        gameState = 99;
      }
    }
  }
  
  if (gameState == 98) {
    winner();
  }
  if (gameState == 99) {
    loser();
  }
}
void PlayGame(byte bound1, byte bound2) {
  leds[Position].setRGB(255, 0, 0);
  if (Position < bound1 + 1 || Position > bound2 + 1) {
    leds[Position - 1].setRGB(0, 0, 0);
  }
  FastLED.show();
  Position++;
  if (Position >= NUM_LEDS) {
    leds[Position - 1].setRGB(0, 0, 0);
    Position = 0;
  }
}

void winner() {
  for (byte i = 0; i < 3; i++) {
    for (byte j = 0; j < NUM_LEDS; j++) {
      leds[j].setRGB(0, 255, 0);
      tone(7, 1000, 250);
    }
    FastLED.show();
    millis();
    clearLEDS();
    FastLED.show();
    millis();
  
  }
  findRandom = true;
  Position = 0;

  gameState = level + 1;
  if (gameState > 6) {
    gameState = 0;
  }
}
void loser() {
  for (byte i = 0; i < 3; i++) {
    for (byte j = 0; j < NUM_LEDS; j++) {
      leds[j].setRGB(255, 0, 0);
      tone(7, 200, 250);
    }
    FastLED.show();
    millis();
    clearLEDS();
    FastLED.show();
    millis();
  }
  gameState = 0;
}
void clearLEDS() {
  for (byte i = 0; i < NUM_LEDS; i++) {
    leds[i].setRGB(0, 0, 0);
  }
}
void winAll(){
  
}

So the game starts only the lights, nothing else happens, no buzzer and button on A3 is not odoing anything.

any idea ?

Of course.

Idea #1: This does nothing...

void winAll() {

}

Idea #2: Do not use magic numbers... give a name to all your pin numbers. "What buzzer?" Sometimes you need a delay after a tone to make it sound (I do not know why).

Idea #3: Post a wiring diagram.

Idea #4: You can not power 60 Neopixels from an Arduino. The Neopixels need external power.

Idea #5: This does nothing 14 of the 20 times invoked:

      millis();

Will you be learning how to program, or are you expecting a copy/pasted lump of code to be fixed for you?