Unofficial Nextion/TJC User Forum

Concatenate three integers to a string?


I currently have three integers being the red green and blue values and I wish to concatenate them to one string in order to pass them to the ESP.
I have added three number fields on the display to visually see that it’s working. Now I wish to delete the numbers and add them to a variable.
I could send them one by one but it would be nicer to send all three in a comma separated string.

My idea is to add a variable as string, and in the event do:

n0.val=r    // this works since n0 is number
n1.val=g   // this works since n1 is number
n2.val=b   // this works since n2 is number
va0.txt=r+","+b+","+g // this fails 

I get the following:

Error:Invalid variable operation:va0.txt=r+","+b+","+g( Double click to jump to code)
Error:Compile failed! 1 Errors, 0 Warnings,

I believe I need to cast the variables to string, how is that done?
If va0 is set to sta = number then I can use va0.val=r+b+g but that is of little use.

What are my options here?

Your option is basically to use the covx function to convert the three numeric values into 3 separate string variables first, and then to concatenate the latter.
Otherwise, depending on the bit width of your R,G, and B values, you might do some bit shifting and mask arithmetics to pack the 3 integers into one, like Nextion does it internally with the RGB565 format.

More details here and here.

1 Like

That worked!

covx r,va1.txt,0,0
covx g,va2.txt,0,0
covx b,va3.txt,0,0

Thank you!

This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).