Go Down

Topic: Nextion, changing text on other page. (Read 589 times) previous topic - next topic

StevenBoon

Feb 25, 2019, 08:55 pm Last Edit: Feb 25, 2019, 08:56 pm by StevenBoon
One more Nextion question:
I have an interface where you can enter a code. If the code is 5411, the Arduino code finds this to be true and sets a button text to "Complete!"

The code:
Code: [Select]

NexButton Matrix = NexButton(1, 2, "b23");          //on page 1
NexButton MSubmit = NexButton(4, 1, "b12");      //on page 4
NexText MHeader = NexText(4, 15, "t1");              //on page 4

void MSubmitPopCallback(void *ptr) {
  if(matrixcode == "5411") {
    MHeader.setText("Correct!");
    Matrix.setText("Compleet!");
  }
  matrixcode = "";
}


All the playing to enter the code is on page 4, and MHeader.txt is working correctly.
The problem is that Matrix.txt doesn't change.

I have been playing and figured that if I make it:
Code: [Select]

NexButton Matrix = NexButton(1, 2, "b2");          //on page 1

the "b2" on page 4 is changed to "Complete!" instead of the b2 on page 1!
So apparently the Nextion doesn't write cross-page.

Does anyone know a solution?

martinius96

Arduino and website programmer

StevenBoon

Well sir, please enlighten me on the correct coding! :)

arduarn

Two things:

The component on the inactive page that you want to change must be vscope global.

When referencing the component you need to say which page it is on (the library is a bit weak in this regard), so either declare the component with the page prefix: NexText t0 = NexText(1, 1, "page1.t0"), or go lower level and write the command manually: sendCommand("page1.t0.txt="cheese").

Go Up