Turn LED on with Serial Monitor and off with button

Hello,

I got a problem with my code:

I want that after “xx1-2-3” is entered in the Serial Monitor, a LED lights up. That works!
But the second step is, that after I pressed a button, the LED should go out. In my programm code, the LED ist just going out, while the button is pressed. After I release is, it lights up again.

Can you help me with this issue?

I tried several times to define an status for the LED, but it didn’t helped.

Thanks in advance

char c;
String Zeile;
String Feld[10];
int FeldAnz;
int LED=11;
int Button=10;


void setup() {
 Serial.begin(9600);
 pinMode(LED,OUTPUT);
 pinMode(Button,INPUT);
 digitalWrite(LED,LOW);
}

String ZeileLesen(){
  Zeile="";
  while(Serial.available()){
    c=Serial.read();
    Zeile+=c;
    delay(2);
  }
  return Zeile;
}

void PositionLesen(){
  FeldAnz=1;
  for(int i=0;i<10;i++){
    Feld[i]="";
     }
  int Len=7;
  int Pos=2;                           
  while((Pos<Len)){
    c=Zeile[Pos];
    Feld[FeldAnz-1]+=c;
    Pos++;
     }
 }


void loop() {
  while(Serial.available()){
    ZeileLesen();
    PositionLesen();
    for(int i=0;i<FeldAnz;i++){
      Serial.println(Feld[i]);
              }
        }
    for(int i=0;i<FeldAnz;i++){           
    if (Feld[i]=="1-2-3"){
    digitalWrite(LED,HIGH);
   
  while(digitalRead(Button)==HIGH){
       digitalWrite(LED,LOW); }
      }
  else{digitalWrite(LED,LOW);
      }
   }
}

I think you need to use an IF statement instead of a WHILE statement on the logic for your button.

IF digitalRead == HIGH, then, turn off LED.

not while digitalRead == HIGH turn off LED.
(Because then with that logic, you are doing the following: while digitalRead == LOW turn ON LED)

here's a conventional way of checking for a button press that is non-blocking

// recognize button presses; tgl LED when pressed

byte butPin = A1;
byte ledPin = 10;

byte butLst;


// -----------------------------------------------------------------------------
void setup (void)
{
    digitalWrite (ledPin, HIGH);
    pinMode      (ledPin, OUTPUT);

    pinMode      (butPin, INPUT_PULLUP);
    butLst      = digitalRead (butPin);
}

// -----------------------------------------------------------------------------
void loop (void)
{
    byte but = digitalRead (butPin);

    if (butLst != but)  {
        butLst = but;

        if (LOW == but)     // button pressed
            digitalWrite (ledPin, ! digitalRead (ledPin));
    }

    delay (10);         // debounce
}