Help please( display Nextion

Help write the rule code please. Esp sends the value in the text line to the display. Watering in the display is also created in the text fields t0.txt.
page0.t0.txt.="[Senseair#pmm]"
I want that when the value in the field changes t0.txt if it gets bigger 500, the font color will change! how to do it how to register conversion correctly?

//if(t0.txt.val>500)
// {
// t0.txt.pco = 1024
//} else
// {
// t0.txt.pco = 0
//}

how to make the correct conversion from text to number for comparing rules

Hello 068alex
Welcome to the Arduino fora.
Before you do anything else please read General guidance
And
How to use this forum
The forum rules are there to help us give you a more helpful answer. At the moment your question is too vague to offer a helpful answer to, and I can't see much sign of you trying to help yourself.
You might also find it useful to read through the tutorial 'Using Nextion displays with Arduino'.
Thank you.

Hello 068alex,

If you want to convert the value of the t0.txt to numeric, use the < cov > command. You just have to create a numeric component, in order to store the converted text (in the following example, n0).

cov t0.txt,n0.val,0

if(n0.val>500)
{
 t0.pco=1024
}else
{
t0.pco=0
}

You must trigger this code somewhere from the event of any component, such as a timer, a button or even a text or a numeric component.

If you want more information about < cov >, you can go to:

Tutorial on how to write code with Nextion and Arduino

And of course the instruction set of Nextion:

Instruction Set - Nextion

Debug

to.txt="700"

my dear friend, it does not work(((((

see((

does not change color

Go to toolbox

Click on the Number component (picture below)

Done. Make sure it is named n0.

If you have further questions, feel free to ask

And also, the code must not be commented. Please remove the // in front of every line

I have tested the code and it is working.

I don’t know what I’m doing wrong (((it’s not working for me (I’m still very stupid probably for such knowledge. Dear friend, I ask you very much to send your project please (in HMI

Ok I have attached the .HMI file and it is working.

Do not hesitate if you have further questions

test.zip (18 KB)

friend I could only check. yes super everything works)) only in two fields then two identical numbers are shown. How to make the field n0 invisible on the screen?

You are going to have to write on the preinitialize event of the page: < vis n0,0 >. This will make the n0 component not visible. I attached the changed file so you can see.

test2.zip (18 KB)

You have a kind heart! You helped me a lot. I wish you all the best my dear friend

if(n0.val>600)
{
n0.pco=64512
}
if(n0.val<600)
{
n0.pco=0
}
if(n0.val>1100)
{
n0.pco=645
}
if(n0.val<1100)
{
n0.pco=64512
}
if(n0.val>1600)
{
n0.pco=512
}
if(n0.val<1600)
{
n0.pco=645
}

But how to make it out of 4 colors? I get a conflict. colors intersect

Hello Alex,

The problem was that you had three < if > that were saying:

if(n0.val<600)
{
  n0.pco=0
}
if(n0.val<1100)
{
  n0.pco=64512
}
if(n0.val<1600)
{
  n0.pco=645
}

So, now the t0.txt , in the beginning is 510. Now the first < if > will change the color of the text to black, because 510 < 600.

Now comes the second < if >, that changes the color of the text to orange, because 510 < 1100.

The third if now also changes the color of the text to dark green, because 510 < 1600.

This way ONLY the final < if > that is executed, will change the color you see of the text, in this case, dark green.

What you should write is:

if(n0.val<600)
{
  t0.pco=0
}
if(n0.val>600&&n0.val<1100)
{
  t0.pco=64512
}
if(n0.val>1100&&n0.val<1600)
{
  t0.pco=645
}
if(n0.val>1600)
{
  t0.pco=512
}

Now the color of the t0 (I guessed this was the component of which you wanted to change the color of the text, as n0 is not visible) will change to black if the value of n0 is less that 600 < n0.val<600 >,

change to orange if it is greater than 600 AND less than 1100 < n0.val>600&&n0.val<1100 >

change to dark green if it is greater than 1100 AND less than 1600 < n0.val>1100&&n0.val<1600 >

and finally change to darker green if it is greater than 1600 < n0.val>1600 >

I have tested it and it is working.

For further questions, do not hesitate to ask.

Thanks all super! Karma plus!

Friend, can you make more less display brightness?

Do you want two buttons?

One to make it less bright and another one to make it brighter?

I can if this is what you want.

EDIT:

I attached the .HMI file.

It has two buttons, one that decreases the brightness and on that increases it.

I wrote in the button's Touch Press Event this:

va0.val-=1 // for lowering brightness
va0.val+=1 // for increasing brightness

// and added this to the timer:
dim=va0.val // I created a variable to store the value of the brightness 
           // the starting value of the brightness is 100
          // the maximum value of the brightness is 100
         // and the minimum value 0

Hope this is what you want. It has been tested and it is working.

test.zip (18.1 KB)

Hello Alex,

Now I made it so a variable is not needed.

The brightness now can't go below 15 and above 100 and is now displayed next to the "Brightness" text.

See it for yourself.

test3.zip (18 KB)

Super! I guess I will run out of questions)) You have so much knowledge, I am surprised! I want to always be in touch with you) I live in Ukraine in Kiev