I think this method inefficent. Because ESP32 continuously listens to the button state.
You will try this method . Working for me .
int R1 = 2;
NexDSButton bt0 = NexDSButton(0, 8, "bt0");
uint32_t dual_state=0;
void setup(){
nexInit();
pinMode(R1, OUTPUT);
}
void loop(){
bt0.getValue(&dual_state);
delay(200);
if(dual_state==1) //When pressed dual state button dual_state =1
{
digitalWrite(R1, HIGH);
}
else if(dual_state==0)
{
digitalWrite(R1,LOW );
}
}