Nextion button and External Push button

Hello. I am new with arduino and nextion, so I need some advices. I have 2 button to ON/OFF 1 LED: one is nextion button and another one is external push button. Now both switches can turn off - turn on the led... But the problem is
if I hold the button, the LED will turn on-off alternately... How do I solve it??
Sorry for my bad english
Here my code

#include <SoftwareSerial.h>

#include <Nextion.h>
SoftwareSerial nextion(10, 11);
Nextion myNextion(nextion, 9600);

int Relay1 = 2;

int Counter1 = 0;

int BoxButton1 = 14;

int ValBox1 = 0;

//------------------------------------------

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

  pinMode(Relay1, OUTPUT);

  pinMode(BoxButton1, INPUT_PULLUP);
  
  digitalWrite(Relay1, HIGH);

  myNextion.sendCommand("p1.pic=1");
}

//-------------------------------------------
void loop()
{
  int bt1 = myNextion.getComponentValue("b1");
  ValBox1 = digitalRead(BoxButton1);

  if ( bt1 == 1 || ValBox1 == 0)
  {
    Counter1 += 1;
    delay(100);
    if ( Counter1 == 1 )
    {
      digitalWrite(Relay1, LOW);
      myNextion.sendCommand("p1.pic=7");
    }
    if ( Counter1 > 1 )
    {
      Counter1 = 0;
      digitalWrite(Relay1, HIGH);
      myNextion.sendCommand("p1.pic=1");
   }
 }
    

Use the state change detection method. With that you can have it act one time for when the button is pressed and the action cannot happen again until the button is released and pressed again. See the state change detection tutorial and my addendum for active low switches.

Try this code. Wire a momentary switch (pushbutton) from pin 4 to ground, load and run the code. If you push the button the state of the onboard LED will toggle and stay in that state even if you hold the button or release the button. The LED will then change state again on the next button press.

// by C Goulding aka groundFungus

const byte  buttonPin = 4;    // the switch is wired to pin 4 and ground
const byte ledPin = 13;       // the pin that the LED is attached to

bool buttonState = 0;         // current state of the button
bool lastButtonState = 0;     // previous state of the button

void setup()
{
   // initialize the button pin as a input with internal pullup enabled
   pinMode(buttonPin, INPUT_PULLUP);
   // initialize the LED as an output:
   pinMode(ledPin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 50;  // check switch 20 times per second
   if (millis() - timer >= interval)
   {
      timer = millis();
      // read the pushbutton input pin:
      buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            // if the current state is LOW then the button
            // went from off to on:
            digitalWrite(ledPin, !digitalRead(ledPin)); // toggle the output
         }
      }
      // save the current state as the last state,
      //for next time through the loop
      lastButtonState = buttonState;
   }
}

@oxyjay, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink: