Problems with Switch/Case statetement, maybe it's something silly

const int led_blu = 11;
const int led_rosso = 10;
const int led_giallo = 9;
const int led_verde = 8;

const int pulsante_b = 46;
const int pulsante_r = 47;
const int pulsante_g = 48;
const int pulsante_v = 49;

const int start = 53;
 
bool superato_0 = false;
bool superato_1 = false;
bool superato_2 = false;
bool superato_3 = false;
bool superato_4 = false;
bool superato_5 = false;
bool superato_6 = false;
bool superato_7 = false;
bool superato_8 = false;
bool superato_9 = false;
bool superato_10 = false;

void setup() {
  Serial.begin(9600);
  randomSeed(analogRead(A0));
  
  pinMode(led_blu, OUTPUT);
  pinMode(led_rosso, OUTPUT);
  pinMode(led_giallo, OUTPUT);
  pinMode(led_verde, OUTPUT);

  pinMode(pulsante_b, INPUT);
  pinMode(pulsante_r, INPUT);
  pinMode(pulsante_g, INPUT);
  pinMode(pulsante_v, INPUT);

  pinMode(start, INPUT); 
  
}


void loop() {

  // conteggio dei livelli:
  int livello = 0;
  
  if (superato_9) livello = 10;
  else if (superato_8) livello = 9;
  else if (superato_7) livello = 8;
  else if (superato_6) livello = 7;
  else if (superato_5) livello = 6;
  else if (superato_4) livello = 5;
  else if (superato_3) livello = 4;
  else if (superato_2) livello = 3;
  else if (superato_1) livello = 2;
  else if (superato_0) livello = 1;
  

  Serial.println(livello);
  delay(500);

  switch(livello){

    case 0:
      Serial.println("default");
      while (true){
        Serial.print(livello);
        Serial.println("In attesa...");
        delay(500);
        
        if (digitalRead(start)) {
          Serial.println("Inizio del gioco");
          superato_0 = true;
          break;
          
        }
      }
      break;
      
    case 1:
      Serial.println("Livello 1: \n");

      // generazione serie random:
      int serie_1[1] = {random(9, 13)};

      // accensione dimostrative dei led:
      for (int led = 0; led < 1; led++){
        digitalWrite(serie_1[led], HIGH);
        delay(1000);
        digitalWrite(serie_1[led], LOW);
      }

      int registro_1[1];
      bool tasto_premuto = false; 
      
      while (true){
        int i = 0; 

        while (i < 1){
          if ( (digitalRead(46) || digitalRead(47) || digitalRead(48) || digitalRead(49)) && !tasto_premuto) {

            // premuto pulsante blu:
            if (digitalRead(46)){registro_1[i] = 12; i++; digitalWrite(12, HIGH); delay(700); digitalWrite(12, LOW); tasto_premuto = !tasto_premuto;}
            // premuto pulsante rosso:
            else if (digitalRead(47)){registro_1[i] = 11; i++; digitalWrite(11, HIGH); delay(700); digitalWrite(11, LOW); tasto_premuto = !tasto_premuto;}
            // premuto pulsante giallo:
            else if (digitalRead(48)){registro_1[i] = 10; i++; digitalWrite(10, HIGH); delay(700); digitalWrite(10, LOW); tasto_premuto = !tasto_premuto;}
            // premuto pulsante verde:
            else if (digitalRead(49)){registro_1[i] = 9; i++; digitalWrite(9, HIGH); delay(700); digitalWrite(9, LOW); tasto_premuto = !tasto_premuto;} 
          }
          
          if ( !(digitalRead(46) || digitalRead(47) || digitalRead(48) || digitalRead(49)) && tasto_premuto) tasto_premuto = false;
        }
        break;           
      }
      
      Serial.print(registro_1[0]);
      Serial.print(" == ");
      Serial.println(serie_1[0]);
      
      if (registro_1[0] == serie_1[0]) {
        Serial.println("BRAVO! Livello 1 superato \n"); 
        superato_1 = true;
      }
      else {
        Serial.println("LIVELLO 1 NON SUPERATO");
      }

      Serial.println(livello);
      break;

    case 2:
      Serial.println("Sta per iniziare il secondo livello..");
      delay(6000);
      Serial.println("Livello 2:");

      // generazione serie random:
      int serie_2[2] = {random(9, 13), random(9, 13)};

      // accensione dimostrative dei led:
      for (int led = 0; led < 2; led++){
        digitalWrite(serie_2[led], HIGH);
        delay(1000);
        digitalWrite(serie_2[led], LOW);
      }
      break;
      
//
//    case 3:
//    break;
//    
//    case 4:
//    break;
//
//    case 5:
//    break;
//    
//    case 6:
//    break;
//
//    case 7:
//    break;
//    
//    case 8:
//    break;
//
//    case 9:
//    break;
//
//    case 10:
//    break;
       
  }
              
}

I came out with this code. it’s purpose is to make leds light in a random generated sequence and then the player has to repeat this sequence. Sorry for the mess and not propertly written code, I’m new to Arduino (I will make it cleaner once I solve this problem).

I can’t figure out why the switch\case statement doesn’t actually works with the variable “livello” even though I have tried many ways in order to make it work. I’m quite sure this could be something very silly, sorry me, thanks for your help.

Thank you for posting using code tags.
I do not know why your switch/case statement does not work. Sorry.
When you are tempted to suffix variable names with numbers, it is time to learn about arrays, except that you seem to know about them… except that having an array with a size of zero or one is fairly useless in C/C++.

My Italian is not so good, and your variable names are therefore a tad incomprehensible to me. but i downloaded the code but it does not compile for one error and i have run into this myself as well. You can not declare variables within a 'case:' of a switch-case. (or eh maybe you can, but i've never managed..) so any variables you want to use need to either be declared before or, if you want them dispoable should be part of a function you can call. Hope that answers your question.

You can not declare variables within a 'case:' of a switch-case. (or eh maybe you can, but i've never managed..)

You can if you enclose the code for the case in { and }

MarcUSB:
I can't figure out why the switch\case statement doesn't actually works with the variable "livello" even though I have tried many ways in order to make it work. I'm quite sure this could be something very silly, sorry me, thanks for your help.

Define 'doesn't work'.

I believe you will never get out of this loop:

while (true) {
  int i = 0;
//.....
}

UKHeliBob:
You can if you enclose the code for the case in { and }

There you go, yes of course ! thanx Bob !