Start a new topic

Button with 3 states

Hi guys,


I am trying to setup a button to have 3 states and more, for example, I am trying to make a button that when I once will set my arduino code to AVERAGE twice it will  set to Peak and 3rd time I press will set to Max Hold.


Anyone has any idea how can I setup such button and get the info on arduino that it should show the info for each state?


I am really stuck on this, if anyone has any idea I would appreaciate a lot.


Regards,

Flopes 


 define a counter-variable. With every button-press, cycle thru this variable according to your number of states you like to have.

 






va0.val=va0.val+1

if(va0.val>2)

{

va0.val=0

}

print va0.val


you either can send out the variable.val after every button-press aka change and trigger an arduino interrupt/routine to catch and act on immediatelly or

you can read out the variable.val directly when you need it by code ...


G.

 

Thanks for the answer Gerhard,


Do you define this counter-variable in the touch press event on the nextion editor?

I guess, there are not too many possibilities, HOW to define a variable ...
'Add Component "Variable"' is your friend ...

 G.

HMI

Hi


thanks for the exemple, in your code you have:

 

va0.val=va0.val+1
if(va0.val>2)
{
va0.val=0
}
cov va0.val,b0.txt,0
print va0.val

 shouldn't it be print b0.txt?

There is no law that forbids one or the other ...  :-) just watch the debugger and see what happens ...
How the button-status-data come to your arduino, that's up to you ...

G.

 

You're right but I am getting always the same response from the arduino serial: 


Button 1

65 0 4 1 ffff ffff ffff ÿÿÿ

Button 2

65 0 5 1 ffff ffff ffff ÿÿÿ


va0.val=va0.val+1
if(va0.val>3)
{
  va0.val=0
}
cov va0.val,b0.txt,0
print va0.val

I am not getting the same as in the Nextion editor debug, why I do not get the 0x01 0x00 etc? 



Thanks for help

 then you must check your Arduino code ...

when sending 'directly' to a terminal programm on PC, you get attached results ... and that's exactly the expected ...


G.

JPG
(38.2 KB)
Login or Signup to post a comment