Nextion - wrting code to avoid multiple pushes

Hey friends

Sometimes i have the problem that when i push a button to fast after another my SerialCommands to my Nextion wont arrive.

So i am thining about to implement some code to prohibit the "user" a fast button push.

For example:

This button hides or makes some elemts visible, depending on the button-state

void Alarm_1PopCallback(void *ptr)                                                              
{
  uint32_t alarmState;
  Alarm_1.getValueDS("Alarm",&alarmState);
  Serial.print("alarmstate: ");
  Serial.println(alarmState);
  if(alarmState==1)
  {
    
    Serial2.print("vis t2,1");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);

    Serial2.print("vis t3,1");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);

    Serial2.print("vis AlarmUg,1");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);

    Serial2.print("vis AlarmOg,1");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    memset(buffer, 0, sizeof(buffer));
    lowerAlarm.getText(buffer,sizeof(buffer));
    init_1._lowerAlarm=String(buffer);
    memset(buffer, 0, sizeof(buffer));
    upperAlarm.getText(buffer,sizeof(buffer));
    init_1._upperAlarm=String(buffer);
    //Serial.println(init_1._lowerAlarm);
    //Serial.println(init_1._upperAlarm);
  }
  else if(alarmState==0)
  {
    
    Serial2.print("vis t2,0");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);

    Serial2.print("vis t3,0");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);

    Serial2.print("vis AlarmUg,0");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);

    Serial2.print("vis AlarmOg,0");
    Serial2.write(0xFF);
    Serial2.write(0xFF);
    Serial2.write(0xFF);
  }
  if(alarmState!=init_1._alarmState)
  {
    init_1._alarmState=alarmState;
    EEPROM.writeInt(PHVALUEADDR + 4*(sizeof(float)), init_1._alarmState);
    EEPROM.commit();
  }
}

A "delay(time)" is no option for me

Anyone an idea?

Thank you

If you want to use an alternative to delay() then take a look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Sometimes I have the problem that when i push a button to fast after another my SerialCommands to my Nextion won't arrive.

When I originally started playing with Nextion displays and devised the methods I explain in 'using Nextion displays with Arduino' I played around with having sliders send their position to the controller (a PIC, but it doesn't make any difference) and the controller immediately respond with an update to the slider position. This resulted in a lot of data back and forth between the Nextion and the controller, but even at 9600 baud everything kept up with everything else without issue, however fast I moved the sliders.

If you are having problems with either the Nextion or whatever you are using to control it not keeping up with the data then I suggest you try the methods I show in the tutorial.

If you really prefer to keep using the Nextion library then note that the original from ITEAD is full of bugs. There is a link from my tutorial to revised Nextion libraries that Ray Livingston made, Ray has removed many of the bugs, his libraries work much better than the originals.