Hello, I am trying to make a multiline text component which is updated with internal Nextion keyboard. I am trying to delete the first line of a text internally and slide the rest of the text on the upper side. I had some couple thoughts but I think without creating a solution for right-side-wise deletion it won’t work. Anyone got any ideas? Will be highly appreciated.
To remove the first part of a string is possible with substr, to find a delimiter (CR) is possible with spstr.
I’m not sure this is the only problem you want to solve.
I found myself looking to do exactly what the OP describes here. This is how I approached it and maybe you guys can comment.
I created a display with a text t0 and a hotspot m0 (hotspot is better than a button here as it uses less memory).
I also added va0 as string and va1 as number.
in the hotspot m0 touch press event I added the following code.
spstr t0.txt,va0.txt,“\r”,0
strlen va0.txt,va1.val
substr t0.txt,t0.txt,va1.val+1,-1
The idea is for the MCU to append text to t0.txt. Then it triggers a click on m0 so that the above code remove the first line. Hence shifting the entire text up and giving a terminal style display.
My arduino code is here below ( I usually use a library but made it pure arduino code for this demo).
#include <SoftwareSerial.h>
SoftwareSerial nextionSerial(4, 5); // RX, TXuint32_t timer1 = 0;
void setup()
{
Serial.begin(9600);
nextionSerial.begin(9600);
nextionSerial.print(“t0.txt=""”);
terminate();
}uint8_t idx = 0;
void loop()
{if ((millis() - timer1) > 1000) {
timer1 = millis();
nextionSerial.print(“t0.txt+="”);
nextionSerial.print(timer1);
nextionSerial.print(“\r"”);
terminate();
idx++;if (idx > 14) { nextionSerial.print("click m0,1"); terminate(); idx--; }
}
}
void terminate() {
nextionSerial.write(0xFF);
nextionSerial.write(0xFF);
nextionSerial.write(0xFF);
}
This sketch just prints the clock time every seconds as demonstration.
Caveat: Using the MCU to control when to remove the first line (after 14 lines in my example) is not ideal. I would much prefer the nextion display to manage this but have not found how. Problem is to know the number of lines efficiently.
Problem: In my example I get a blank space on the first line which I can’t figure out to remove. ANy ideas?
If you think of a better way to do this and keeping it rather lightweight feel free to suggest. Thank you.
Isn’t there a delete key?
The famous \r is two bytes 0x0D 0x0A. Your approach with substr eliminates only one of both, leaving the orphaned 0x0A.
substr t0.txt,t0.txt,va1.val+2,-1 will solve your problem.