How to use Eternal push button with Nextion touchscreen display Button

Hi all

Can someone help me about the code for arduino,

I alreay make push button on Nextion on b0 and make extenal push button connect on pin 2 for arduino and led pin3 for output

I need when i push extenal push button. The Nextion push button will effect too.

It mean the Led pin3 will work when I push both external button and Nextion push button

Thank you

#include "Nextion.h"
 
NexPicture p0 = NexPicture(0, 1, "p0");
NexPicture p1 = NexPicture(0, 4, "p1");
NexButton b0 = NexButton(0, 2, "b0");
NexButton b1 = NexButton(0, 3, "b1");
const int buttonPin = 2; 
int buttonState = 0;  
const int ledPin =  13; 
char buffer[10] = {0};
 
NexTouch *nex_listen_list[] = 
{
    &p0,
    &p1,
    &b0,
    &b1,
    NULL
};
 
void p0PopCallback(void *ptr)
{
    uint32_t number1 = 0;
    dbSerialPrintln("p0PopCallback");
 
    p0.getPic(&number1);
 
    if (number1 == 1)
    {
        number1 = 2;    
    }
    else
    {
        number1 = 1;
    }
     
    p0.setPic(number1);
}
void b0PopCallback(void *ptr)
{
    NexButton *btn = (NexButton *)ptr;
    memset(buffer, 0, sizeof(buffer));
  
    btn->getText(buffer, sizeof(buffer));
 
  
    if (strcmp(buffer,"ON"))
    {
       // digitalWrite(ledPin, HIGH);
        strcpy(buffer, "ON");
    }
    else
    {
        digitalWrite(ledPin, HIGH);
 
        strcpy(buffer, "OFF");
    }
    btn->setText(buffer);
     
}
 
void b1PopCallback(void *ptr)
{
    NexButton *btn = (NexButton *)ptr;
    memset(buffer, 0, sizeof(buffer));
    btn->getText(buffer, sizeof(buffer));
    if (strcmp(buffer,"BACK"))
    {
        //digitalWrite(ledPin, HIGH);
        strcpy(buffer, "BACK");
    }
    else
    {
        //digitalWrite(ledPin,HIGH);
        strcpy(buffer, "OFF");
    }
    btn->setText(buffer);
    
}
 
void setup(void)
{
   dbSerial.begin(9600);
    nexInit();
    p0.attachPop(p0PopCallback);
    b0.attachPop(b0PopCallback, &b0);
    b1.attachPop(b1PopCallback, &b1);
     
    dbSerialPrintln("setup done");
     pinMode(buttonPin, INPUT);
     pinMode(ledPin, OUTPUT);
 
  digitalWrite(ledPin,HIGH);
}
 
void loop(void)
{
    nexLoop(nex_listen_list);
  buttonState = digitalRead(buttonPin);
 uint32_t number2 = 0;
  
     if (buttonState == LOW) {
    p1.getPic(&number2);
   
   if (number2 == 1)
    {
        number2 = 3; 
        digitalWrite(ledPin,LOW); 
         
        
    } 
 
       else
    {
        number2 = 1;
    }
  p1.setPic(number2);
 
   }
 
 
}

Either read both buttons in the same place in the code, or make yourself a couple of booleans and set them when you read the buttons instead of turning on or off the led and do the led on or off thing in the loop based on the states of the two boolean.

Thank you for your reply Delta_G

I understand your point more clear.So now my problem is I what is the code the I can use for push nextion button by using externaly push button

here is a format return data.

but I do not know how to use with arudino which code I need to use

Thank you for your all kinds