Start a new topic

How to use "vis: Hide / show component" with an Arduino controller ??

 

va10.val=0
if(va10.val==1)
{
  vis p3,1
}
if(va10.val==0)
{
  vis p3,0
  vis p4,1
}


 

 Hello everyone.
All first I am sorry for my english I translated with Google.

I started with Arduino and Nextion screen.
Looking how to use "vis: Hide / show component" which is in Nextion Instruction Set. the command comes from the Arduino 0 or 1 for displayed or not an image according to the state (1 displayed, 0 not displayed).


Here's the code I wrote in Nextion éditor, I do not know if I wrote it in the right place (Postinitialize event execute after refresh of all components).
I have no compiler error but its not working.


There it among the members of the forum, someone who could explain to me.
Thank you in advance.
Cordially.

 

va10.val=0
if(va10.val==1)
{
  vis p3,1
}
if(va10.val==0)
{
  vis p3,0
  vis p4,1
}

 


according to your posted code:


va10.val=0            // set va10 to 0

if(va10.val==1)      // skips over as va10 is not 1

{

  vis p3,1                     // would have shown p3  visible is on

}

if(va10.val==0)      // will execute these as va10 is 0

{

  vis p3,0               //  hides p3  as visible is off

  vis p4,1               //  shows p4 as visible is on

}


So with this code in the Postinitialize event, p4 should be showing, and p3 hidden.

va10 only stores a value and does not trigger any code.

In the code, p4 starts visible by default and should always be visible - a redundant line.

If the pictures p3 and p4 are stacked on top of each other, it will be more complicated


Now to use vis through your Arduino

- you need to send vis p3,0 over serial followed by three bytes of 0xFF (or the char(255)  ÿ).

- the three bytes 0xFF 0xFF 0xFF or ÿÿÿ is the data terminator for all commands over serial.

- how you send it depends on which library you are using.

serial.print("vis p3,0ÿÿÿ");

or with the IteadLib using sendCommand includes the terminators inside the sendCommand routine

sendCommand("vis p3,0");


I am not certain that all of this needs to be wrapped within a variable va10, so not knowing what other logic is being used in your program, it is also possible to issue vis p3,va10.val provided va10.val is only ever 1 or 0.  This still hasn't addressed how you trigger the code. 


If the trigger is external on the Arduino, you should be triggering the code from your Arduino code and not the Nextion.  If the trigger is through user interaction via your HMI design, then your trigger should be in Nextion code and not on the Arduino.  One should trigger and then update the other, you need to decide.


Hope some of this is helpful

Hello Patrick
Thank you for your reply, its frankly my help,
I only use the Serial library
Thanks to your method I managed posted or not the image in Nextion screen.
The order is placed since the Arduino (see code), I removed the code in the Nextion screen.
It works very well.


Thank you for your help.
Cordially


Arduino code:

  if (barProgressRpm>= 30)
  {
  Serial.print("vis p4,0");   
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  //Serial.print("\n\r\n\r");// just to see the Arduino serial monitor
  }
  else
  {
  Serial.print("vis p4,1");   
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  //Serial.print("\n\r\n\r");//just to see the Arduino serial monitor   
  }

Login or Signup to post a comment