I am trying to change the arduino sketch to use the nextion.h library. I can get it to work for sending a letter from the nextion to my computer. It is also working to use the arduino serial monitor to send a color change to the nextion button.
My issue is that I can’t figure out how to send a color change from serial monitor to nextion with the library.
I am using a promicro with SoftwareSerial.h
#include <Nextion.h> // Nextion Library
#include <SoftwareSerial.h> // Library for Software Serial Port
#include <Keyboard.h> // Keyboard Emulation
SoftwareSerial mySerial(9, 10); // RX, TX
char incomingByte; // for incoming serial data from computer
// This part is used to declare all the objects we can receive from the Nextion Display
// (page, ID, Object name)
NexButton b0 = NexButton(0, 1, “b0”); // “TEST” Button on Page 0
// This part is used to list the possible touchscreen events in an Array
NexTouch *nextion_touch_events[] =
{
&b0, // Page 0 Button 0
NULL // End string
};
// This part is for the different functions for Main Screen Touch events (page zero)
void b0PushCallback(void *ptr)
{
Keyboard.press(‘t’); // ‘t’ for TEST
delay(250); // Delay of 250ms to register the key press
Keyboard.release(‘t’); // stop pressing the key
}
//________________________________________________________
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
Keyboard.begin();
nexInit(); // Nextion Display initalize
// Link the touchscreen events to their relative functions in the code
// attachPush for press events or attachPop for release events
b0.attachPush(b0PushCallback);
}
//_______________________________________________________________________________
void loop() {
delay(100); // small delay before checking again for touch events
nexLoop(nextion_touch_events); // Check for any touch event and run the associated function
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
}
if (incomingByte == 'b' || incomingByte == 'B') // turn button 0 white
{
mySerial.print("b0.bco=65535");
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
}
if (incomingByte == 'o' || incomingByte == 'O') // turn button 0 green
{
mySerial.print("b0.bco=28320");
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
}
}