I don’t believe it’s possible to interrupt a loop with a touch event. I ‘want’ to be able to touch a ‘STOP’ button on the HMI to stop the countdown timer which is displaying on screen.
In your WHILE/FOR loop, check the tch0 and tch1 values. These indicate the current touch positions (x,y coords). If they indicate a valid touch location then “STOP”
I’d just like to confirm that using tchX worked perfectly for me.
So a big word of thanks to you for that suggestion as I’d been battling to find a way to exit a while loop when the button was released, but had given up thinking it was not possible with a Nextion.
I wanted a button press to repeatedly send a serial byte every so many milliseconds while the button is pressed but stop sending the byte (i.e. end the while() loop) as soon as I released the button.
I made this code:
while(tch0!=0)
{
printh 09
delay=50
}
And it worked perfectly. So once again thanks very much.
Timers are this what is dedicated for such things.
You can put this code into timer object ex. tm0.
Make sure that tm0.en=0 and tm0.tim=50 so it is not runnign if button is not pressed.
By pressing button You may activate this timer to mak it running.
Button touch press code:
tm0.en=1
Button toch release code
tm0.en=0
Timer tm0 code:
printh 09
This approch doesn’t block other tasks runnign in the background.
I’d heard about timers to do this but didn’t know how they worked. Just tried your instructions and it worked perfectly.
This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).