Start a new topic

do loop

 Hi All

Is it possible with to do a do loop with the nextion such as

if a button or hotspot pressed

then whilst the button is pressed  say

print "F"


get return value

update txt


keep printing F until button/hotspot released



Very unclear question.  Sorry.

Nextion does not have a do loop

Nextion doesn't get return values

In defining what you are asking more specifically

 - I think you will define the logic needed to do what you ask

Assuming I understand correctly (assuming what is not stated)

   the separation of Nextion duties and MCU duties

Then Yes. And perhaps several ways to achieve.

Hi Patrick
sorry for the lack of clarity
what I am try to achive (which I have using the timer varable) is
a , + or - button is pressed and held down
whilst the user holds down either the nextion print (sends) a character
the MCU recieves this character and determines which value to inc or dec
and response by updating a text block on the screen.
Like I mentioned above I have acomplised this using the timer variable
but was interested if this can be done without using the timer variable
how I have it constructed at the moment is
value to be changed button selected (ie month) sets value.val ie 1
then via the + or - hotspot
if( value.val==1) //(then the + or - button selected)
(then in tm0 the following)
print "Z" (MCU inc or decs respective variable)
cov t0.txt,month.val,0// (MCU updates t0.txt with the respective value)
on return to pressed event
if (month.val==1)
cov month.val,t1.txt,0
whilst the hotspot still active bounces back to  tm0 hence inc or decing
the MCU's variable forming the loop
hope this clearer
kind regards


Doing it that way, you can never be sure that the incremented or decremented values are identical on Nextion and MCU.

Variables should be held only once (no redundancy and no sync problems), preferably in the MCU if these will be used there. From that, MCU should update the displayed values.

Thus, the correct approach approach: 

- On button press send id to MCU. 

- MCU starts intervalTimer object which will on each tick (via callback functions dynamically attached depending on id)

-- first increment or decrement (depending on button) the corresponding value

-- send the new value back to the Nextion

- On button release send id to MCU.

- MCU stops intervalTimer object.

I might take the approach such that

 - the HMI device is allowed to process and capture user input,

 - until the release has occurred that user input is being captured

 - and then once the release has occurred report to the MCU

ON press, Nextion Logic to inc/dec value within range

ON release, send 0x65 notice to the MCU 

MCU then uses get command to retrieve user input value.

This approach perhaps saves timer code and serial traffic.

Also, since month is numeric 1 to 12

- there is little reason to use a Text Component and cov commands

- Using a Number Component saves conversions.

One Variable Component to hold step value for inc/dec of -1,0,1

One Number Component for visual of value

One Timer Component that on trigger adds step to Number

Button Press then

  sets the step value

  starts the timer

Button Release

  Send Component ID

  Stops the timer

  Sets the step value back to 0


Multiple Buttons doing the same inc/dec logic 

 - add Variable for component ID to number Value

0x65 Return Code already contains which Button.

If this is indeed for date and time settings

 - then reserve all communications for a "Done" button

 - MCU then only needs to fetch 2 Variables

Cuts much code, cycles and serial

I stand corrected. Patrick’s approach is definitively more efficient. My apologies.

lol 1000 roads lead to Rome ... as long as one gets there before the Games start

Thank you gentlemen
For your comments I was looking for just such a simpler aproach
what time do the games start
kind regards


simpler ? 

You could use the Nextion keyboard and just let the users type the numbers in

Have a done button on the page when they are finished

Login or Signup to post a comment