Problem with buzzer active

Hi, i have buy buzzer active sunfounder but i have a problem:

My program read from serverweb a string for example <1><0><0><0><1> this string active led red an buzzer, then i active led red and buzzer, then if i touch button turn of led red and buzzer. I have try code but only led turn on buzzer doesn’t sound why?
I have noticed that ony i put buzzer in cycle it sound for example while(true) analogWrite(buzzer,0); why?

#include <SPI.h>
#include <Ethernet.h>
 

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192,168,1,101);
 

EthernetClient client;
 
char server[] = "server";
String PostData = "user=user&passw=passw";

int valore = 0;
int pinDaAttivare = 0;

boolean datoCambiato = false;
boolean buzzerAttivo = false;

const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4;
const int ledPin4 = 5;
const int ledPin5 = 6;
const int ledPin6 = 7;
const int ledPin7 = 8;

//Pin bottone
const int button = 9;

//Pin buzzer
const int buzzer = 10;

void setup() {
  
  Serial.begin(9600);

//Imposto le uscite per i led
  pinMode(ledPin1,OUTPUT);
  pinMode(ledPin2,OUTPUT);
  pinMode(ledPin3,OUTPUT);
  pinMode(ledPin4,OUTPUT);
  pinMode(ledPin5,OUTPUT);
  pinMode(ledPin6,OUTPUT);
  pinMode(ledPin7,OUTPUT);

//Imposto il pin bottone come ingresso di segnale
  pinMode(button,INPUT);

//Imposto il pin buzzer come uscita di segnale
  pinMode(buzzer,OUTPUT);

//Imposto le uscite ai led a 0  
  digitalWrite(ledPin1,LOW);
  digitalWrite(ledPin2,LOW);
  digitalWrite(ledPin3,LOW);
  digitalWrite(ledPin4,LOW);
  digitalWrite(ledPin5,LOW);
  digitalWrite(ledPin6,LOW);
  digitalWrite(ledPin7,LOW);
  
//Imposto il buzzer a silenzioso
  analogWrite(buzzer,255);
  
  Serial.println("Attendo di avere un indirizzo IP usando DHCP:");
  if (!Ethernet.begin(mac)) {
    
    Serial.println("Impossibile avere un IP provare manualmente");
    Ethernet.begin(mac, ip);
  }
 
  Serial.print("Il mio indirizzo:");
  Serial.println(Ethernet.localIP());
  
}


void loop() {

   
    if (datoModificato()) {

    premiBottonoPerDisattivare();

  }
    
  
}

void premiBottonoPerDisattivare() {

  int spenti = 0;

  while (spenti == 0) {

    boolean value = digitalRead(button);
    
    if (value == LOW) {

      resettaServer();
      resettaAZero();
      spenti = 1;

    }

    //delay(200);

  }

}

boolean datoModificato() {

  Serial.println("Controllo Sato");
  if (client.connect(server, 80))
  {


    Serial.println("Connessione...");
    Serial.println("ARDUINO: Preparazione richiesta messaggio HTTP");


    client.print("POST /mysite.php");
    client.println(" HTTP/1.1");
    client.print("HOST: ");
    client.println(server);
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(PostData.length());
    client.println();
    client.println(PostData);

    Serial.println("ARDUINO: messaggio HTTP inviato");


    delay(1000);

    //controlla la risposta dal server, se disponibile,
    //prelevo e stampo il dato ricevuto
    if (client.available())
    {

      
       Serial.println("Connessione...");
    Serial.println("ARDUINO: Preparazione richiesta messaggio HTTP");


    client.print("POST /mysite.php");
    client.println(" HTTP/1.1");
    client.print("HOST: ");
    client.println(server);
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(PostData.length());
    client.println();
    client.println(PostData);

    Serial.println("ARDUINO: messaggio HTTP inviato");


    delay(1000);

    //controlla la risposta dal server, se disponibile,
    //prelevo e stampo il dato ricevuto
    if (client.available())
    {
      Serial.println("ARDUINO: messaggio HTTP ricevuto");
      Serial.println("ARDUINO: prelevo e stampo il dato ricevuto...\n");
      String dato = "";

      int i = 0;
      int evento = 0;
      while (client.available()) {

        char c = client.read();
        //Serial.print(c);
        if (c == '<') {
          c = client.read();
          while (c != '>') {

            //Serial.print(c);
            dato = dato + c;
            c = client.read();

          }

          valore = dato.toInt();
          if (valore != 0) {

            String myString = String(evento);
            attiva(myString);
            datoCambiato = true;

          }

          dato = "";
          evento++;
          i++;

        }


      }


        
    }
    else
    {
      Serial.println("ARDUINO: no response received / no response received in time");
    }

    client.stop();
  }

  
  return datoCambiato;

  }
}

void attiva(String val) {

  if (val == "0") {

    Serial.println("Led Rosso");
    digitalWrite(ledPin1, HIGH);

  } else if (val == "1") {

    digitalWrite(ledPin2, HIGH);

  } else if (val == "2") {


    digitalWrite(ledPin3, HIGH);

  } else if (val == "3") {

    digitalWrite(ledPin4, HIGH);
  
  } else if (val == "4") {

    digitalWrite(buzzer, LOW);
    buzzerAttivo = true;   
      

  }


}


void resettaAZero() {

  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin4, LOW);
  digitalWrite(buzzer, HIGH);
  datoCambiato = false;

}
const int buzzer = 10;

Some Arduinos use pins 11, 12, and 13 for SPI. On those Arduinos, pin 10 is the slave select pin for the Ethernet shield and is used to announce that the Arduino is an SPI master. You can't use that pin for a buzzer.

So, which Arduino do you have?

PaulS: const int buzzer = 10;

Some Arduinos use pins 11, 12, and 13 for SPI. On those Arduinos, pin 10 is the slave select pin for the Ethernet shield and is used to announce that the Arduino is an SPI master. You can't use that pin for a buzzer.

So, which Arduino do you have?

I have arduino uno with ethernet shield why?

I use delay for button but it isn't precise there is an other solution? This is code:

 while (spenti == 0) {

    boolean value = digitalRead(button);
//    if(buzzerAttivo){
//
//      digitalWrite(buzzer, LOW);
//      
//    }
    if (value == LOW) {

      resettaServer();
      resettaAZero();
      spenti = 1;

    }

    delay(200);

  }

I have arduino uno with ethernet shield why?

The Uno uses SPI (pins 10, 11, 12, and 13) to talk to the Ethernet shield.

I use delay for button but it isn't precise

The call to delay() will take 200 milliseconds plus a few hundred nanoseconds for the function call and return. What is "not precise" about that?

there is an other solution?

That depends. What is the problem that needs a solution?