Bonjour à tous,
Je cherche à changer la couleur du texte sur un écran Nextion.
J'arrive bien à le faire avec ce sketch:
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
changeColor(0);
}
void loop() {
// put your main code here, to run repeatedly:
}
//Change color text t0 (exemple : t0.pco)
void changeColor(byte textNo) {
char comd[20];
char temp[20];
strcpy(comd, "t");
sprintf(temp, "%01d.pco=65535", textNo);
strcat(comd, temp);
Serial.println (comd);
Serial3.print(comd);
Serial3.write(0xff);
Serial3.write(0xff);
Serial3.write(0xff);
}
qui donne comme résultat : t0.pco=65535
Maintenant, je souhaiterai pouvoir à la fois choisir le numéro de la Textbox et la couleur du texte.
Malgré tous mes essais pour modifier ce sketch, je n'arrive pas à obtenir le bon code à envoyer à l'écran.
En fait, je m'embrouille avec le sprintf.
Voici mon sketch( qui ne fonctionne pas!)
const char t1;
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
Serial.println("Test");
nextionSendcolor(t1, 63488);
}
void loop() {
// put your main code here, to run repeatedly:
}
void nextionSendcolor (const char *ID, const char *color)
{
char buf[100];
int len = sprintf (buf, "%u.pco=\"%d\"", ID, color);
Serial.println(buf);
Serial3.write(buf, len);
Serial3.write(0xff);
Serial3.write(0xff);
Serial3.write(0xff);
}
Résultat :
Test
0.pco="-2048"
Pouvez vous m'aider?
Merci.