Clearing multiple button push events - Nextion Display

Hi,

I have a sketch that detects a button push event from the Nextion display and goes off and does something for a second or so.

While this activity is taking place if the button is pressed again (or multiple times) it queues up the presses and then essentially repeats the activity.

What I want is a single event and then to somehow at the end of the event to clear the additional button press events so the event doesn't run again. do I need to clear the serial input buffer? I can post the code, but it is pretty generic...

Can anyone help?

Start by posting your code

Here is the Code, the event is m8PushCallBack, essentially it beeps a buzzer and triggers a pulse transformer via pin 2:

#include <Nextion.h>
int calvoltage = 0;
int setcalvoltage = 0;
bool Set10 = false;

NexHotspot m0 = NexHotspot (10, 3, “m0”);
NexHotspot m1 = NexHotspot (10, 4, “m1”);
NexHotspot m2 = NexHotspot (10, 5, “m2”);
NexHotspot m3 = NexHotspot (10, 6, “m3”);
NexHotspot m4 = NexHotspot (10, 8, “m4”);
NexHotspot m5 = NexHotspot (10, 9, “m5”);
NexHotspot m7 = NexHotspot (10, 11, “m7”);
NexHotspot m8 = NexHotspot (10, 12, “m8”);
NexPage page10 = NexPage(10,0, “page10”);

NexTouch *nex_listen_list =
{
&m0,
&m1,
&m2,
&m3,
&m4,
&m5,
&m7,
&m8,
&page10,
NULL
};

void m7PushCallBack(void *ptr)
{
setcalvoltage = calvoltage;
Serial.print(“n1.val=”);
Serial.print(setcalvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void m0PushCallBack(void *ptr)
{
calvoltage = calvoltage + 1;
if (calvoltage > 2500) calvoltage = 2500;
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void m1PushCallBack(void *ptr)
{
calvoltage = calvoltage - 1;
if (calvoltage < 0) calvoltage = 0;
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void m2PushCallBack(void *ptr)
{
calvoltage = calvoltage - 100;
if (calvoltage < 0) calvoltage = 0;
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void m3PushCallBack(void *ptr)
{
calvoltage = calvoltage + 100;
if (calvoltage > 2500) calvoltage = 2500;
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void m4PushCallBack(void *ptr)
{
calvoltage = calvoltage + 10;
if (calvoltage > 2500) calvoltage = 2500;
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void m5PushCallBack(void *ptr)
{
calvoltage = calvoltage - 10;
if (calvoltage < 0) calvoltage = 0;
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void m8PushCallBack(void *ptr) // single pulse application from page 10 (calibration page)
{
analogWrite (5,(map(calvoltage,0,2500,0,250)));
delay(400);
tone(6,400);
delay(600);
noTone(6);
digitalWrite(2,HIGH);
delayMicroseconds(10);
digitalWrite(2,LOW);
analogWrite (5,0); //Set the HV back to 0V
}

void page10PushCallBack(void *ptr)
{
Set10 = true;
}

void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode (5, OUTPUT);
pinMode (2, OUTPUT);
pinMode (6, OUTPUT);
m0.attachPush(m0PushCallBack);
m1.attachPush(m1PushCallBack);
m2.attachPush(m2PushCallBack);
m3.attachPush(m3PushCallBack);
m4.attachPush(m4PushCallBack);
m5.attachPush(m5PushCallBack);
m7.attachPush(m7PushCallBack);
m8.attachPush(m8PushCallBack);
page10.attachPush(page10PushCallBack);
}

void loop() {
// put your main code here, to run repeatedly:
nexLoop(nex_listen_list);

if (Set10 = true)
{
Serial.print(“n0.val=”);
Serial.print(calvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print(“n1.val=”);
Serial.print(setcalvoltage);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Set10 = false;
}

}

Hi, solved this, a bodge but it works... as the code I want to run is always 1 second, I simply added a 1 second delay in the HMI editor for the particular button. The code runs ok but you can't press the button again for a second.

Works for this application...