Code stops working after adding additional if statements

#include <SevSeg.h>
// A=2, B=3, C=4, D=5, E=6, F=7, G=8, DP=9:           // 7 seg display pin numbers

#define NOTE_C5  523                                  // Define Note frequency (Hz)
#define NOTE_D5  587
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_G5  784

SevSeg sevseg;                                        // Create 7-segment display variable
const int button = 0;                                 // Analog pin for determining which button was pressed
const int Buzz = 11;                                  // Buzzer PWM Digital I/O Pin

void setup() {
  byte numDigits = 1;                                 // only one digit display
  byte digitPins[] = {};                              // not important to specify digit pins for one digit
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};      // set segment pins in order A,B,C,D,E,F,G etc
  bool resistorsOnSegments = true;                    // resistor is in series with segment pins
  byte hardwareConfig = COMMON_CATHODE;               // segments share common cathode (-) terminal
  pinMode(button, INPUT);                            // Make analog pin an input
  sevseg.begin(hardwareConfig, numDigits, digitPins,segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
  Serial.begin(9600);
}

void loop() {
  const int buttonState = analogRead(button);
  Serial.print(buttonState);
  Serial.print("\n");
  
  // Detect Button 1
  if (1010 >= buttonState >= 993)
  {
     tone(Buzz, NOTE_C5);
     sevseg.setChars("C");
     sevseg.refreshDisplay();
  } else{
    noTone(Buzz);
    sevseg.blank();
    sevseg.refreshDisplay();
  }

  // Detect Button 2
  if (990 >= buttonState >= 960)
  {
     tone(Buzz, NOTE_D5);
     sevseg.setChars("D");
     sevseg.refreshDisplay();
  } else{
    noTone(Buzz);
    sevseg.blank();
    sevseg.refreshDisplay();
  }

  // Detect Button 3
  if (945 >= buttonState >= 919)
  {
     tone(Buzz, NOTE_E5);
     sevseg.setChars("E");
     sevseg.refreshDisplay();
  } else{
    noTone(Buzz);
    sevseg.blank();
    sevseg.refreshDisplay();
  }

  // Detect Button 4
  if (850 >= buttonState >= 816)
  {
     tone(Buzz, NOTE_F5);
     sevseg.setChars("F");
     sevseg.refreshDisplay();
  } else{
    noTone(Buzz);
    sevseg.blank();
    sevseg.refreshDisplay();
  }

  // Detect Button 5
  if (720 >= buttonState >= 670)
  {
     tone(Buzz, NOTE_G5);
     sevseg.setChars("G");
     sevseg.refreshDisplay();
  } else{
    noTone(Buzz);
    sevseg.blank();
    sevseg.refreshDisplay();
  }
                           
}

So long story short, made small piano with piezo buzzer and 5 buttons. All 5 buttons go to one analog pin to save board space. I used various resistor values for each switch to be compared wiht a 100K ohm resistor as a voltage divider. This is how i determine which button was pressed by checking range of serial read on that pin. It works with the first if statement flawlessly, playing the write note and displaying on screen, and when i let go the display clears and the note stops playing. But after the other if statements nothing works. Think i overloaded it with if statements. Tried all sorts of delay() etc in hopes of giving it time to process but no. Wiring and everything works great and have tested each individual if statement and they each work a a standalone but not all together.

add Serial.begin(115200); to your sketch and add Serial.println with meaningfull comments so you can see what your sketch is doing

if you do it in each if and else you will see what's wrong with the code.

spoiler:

if (990 >= buttonState >= 960)
{

else

is not doing what you want.

then next problem if you have corrected the if:

The else part will be processed for each button - so it might be, that the first button starts the tone - but microseconds later the else of the next button will switch off the tone.

Hello jacobAndrew101

if (945 >= buttonState >= 919)

945 >= buttonState is evaluated.
The result is true or false , so 1 or 0.
Then the result is compared to 919.

Regards,
bidouilleelec

To all who replied, thank you, I fixed my conditionals and have changed the overall structure of the if, else if, else statements to actually function correctly. Piano now works, all 5 buttons are off of one analog pin, and my 7 segment display shows the note that is currently being played. When you let go of a button the note stops playing and the display clears. Thanks for the help. First post on here.

#include <SevSeg.h>
// A=2, B=3, C=4, D=5, E=6, F=7, G=8, DP=9:           // 7 seg display pin numbers

#define NOTE_C5  523                                  // Define Note frequency (Hz)
#define NOTE_D5  587
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_G5  784

SevSeg sevseg;                                        // Create 7-segment display variable
const int button = A3;                                 // Analog pin for determining which button was pressed
const int Buzz = 11;                                  // Buzzer PWM Digital I/O Pin

void setup() {
  byte numDigits = 1;                                 // only one digit display
  byte digitPins[] = {};                              // not important to specify digit pins for one digit
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};      // set segment pins in order A,B,C,D,E,F,G etc
  bool resistorsOnSegments = true;                    // resistor is in series with segment pins
  byte hardwareConfig = COMMON_CATHODE;               // segments share common cathode (-) terminal
  pinMode(button, INPUT);                            // Make analog pin an input
  sevseg.begin(hardwareConfig, numDigits, digitPins,segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
  Serial.begin(115200);
}

void loop() {
  const int buttonState = analogRead(button);
  Serial.print(buttonState);
  Serial.print("\n");
  
  // Detect Button 1
  if (buttonState >= 994 && buttonState <= 1020)
  {
     tone(Buzz, NOTE_C5);
     sevseg.setChars("C");
     sevseg.refreshDisplay();
  } 
  else if (buttonState >= 960 && buttonState <= 990) {
    tone(Buzz, NOTE_D5);
    sevseg.setChars("D");
    sevseg.refreshDisplay();
  }
  else if (buttonState >= 919 && buttonState <= 945) {
     tone(Buzz, NOTE_E5);
     sevseg.setChars("E");
     sevseg.refreshDisplay();
  } 

  else if (buttonState >= 780 && buttonState <= 890){
     tone(Buzz, NOTE_F5);
     sevseg.setChars("F");
     sevseg.refreshDisplay();
  }

  else if (buttonState >= 670 && buttonState <= 720){
     tone(Buzz, NOTE_G5);
     sevseg.setChars("G");
     sevseg.refreshDisplay();
  } 
  else {
      noTone(Buzz);
      sevseg.blank();
      sevseg.refreshDisplay();
  }
  delay(100);                           
}