Howdy,
Full disclosure I normally work as an accountant so this is a little outside of my knowledge base. This is a project for a nonprofit Org.
Im building a remote control transmitter (works fine) and I have the GUI working as I want in the Nextion editor. Now I just want to fetch the number box values to manipulate the outputs of the potentiometers/joysticks. For example if the steering is a little right, click the left button, number goes to -10 on the nextion display and the arduino output is pin A9 - 10. pretty simple.
In my logical mind there should be an easy solution like fetch NexNumber(x,y, "n0") and jobs done. Then have a touch press event to save all the fetched numbers to EEPROM.
But Im struggling to get the number from the display to the Arduino and serial monitor just to make sure Im getting it. I have attached the code. Maybe its the multiple pages? Im just getting diamonds with questions marks or 0s. It should be really easy but for some reason Im not understanding it or over complicating it.
Im only really focused at getting n0 on page 1, page 0 is a home screen the rest of the pages are similar as page 1 fyi. I figure once I get one number from one page I can finish the rest.
Hardware arduino mega, 4 pots A5:A9, NRF24L01, capacitors and voltage regulators, Nextion 3.5 lcd Nx4832T035_011 plugged into rx1/tx1 using iteadlib arduino nextion library
See attached code: just a test code for the screen/arduino communication and serial print
#include <Nextion.h>
int CurrentPage = 0;
//Declare pages
NexPage page0 = NexPage(0,0, "page0");
NexPage page1 = NexPage(1,0, "page1");
NexPage page2 = NexPage(2,0, "page2");
NexPage page3 = NexPage(3,0, "page3");
NexPage page4 = NexPage(4,0, "page4");
NexPage page5 = NexPage(5,0, "page5");
//declare buttons, texts, numbers etc
//Page0 Home Page
NexText t1 = NexText(0,2, "t1"); //title
NexText t2 = NexText(0,3, "t2"); // title
NexText t3 = NexText(0,4, "t3"); // title
NexText t4 = NexText(0,5, "t4"); // title
NexText t5 = NexText(0,6, "t5"); // title
//Page1 Steering
NexButton b0 = NexButton(1,4, "b0"); //trim adjust left
NexButton b1 = NexButton(1,5, "b1"); // trim adjust right
NexButton b2 = NexButton(1,14, "b2"); // home button
NexNumber n0 = NexNumber(1,7, "n0"); //trim number
NexVariable va0 = NexVariable(1,6,"va0");
//Declare touch even objext to the touch even list
//you just need to dd the names of objexts that sent touch event
//format &<object name>
NexTouch *nex_listen_list[] =
{
&page0,
&page1,
&page2,
&page3,
&page4,
&page5,
&t1,
&t2,
&t3,
&t4,
&t5,
&b0,
&b1,
&b2,
&n0,
&va0,
NULL
};
//touch events:
// Page change event:
void page0PushCallback(void *ptr) // If page 0 is loaded on the display, the following is going to execute:
{
CurrentPage = 0; // Set variable as 0 so from now on arduino knows page 0 is loaded on the display
} // End of press event
// Page change event:
void page1PushCallback(void *ptr) // If page 1 is loaded on the display, the following is going to execute:
{
CurrentPage = 1; // Set variable as 1 so from now on arduino knows page 1 is loaded on the display
} // End of press event
// Page change event:
void page2PushCallback(void *ptr) // If page 2 is loaded on the display, the following is going to execute:
{
CurrentPage = 2; // Set variable as 2 so from now on arduino knows page 2 is loaded on the display
}
void page3PushCallback(void *ptr)
{
CurrentPage = 3;
}
void page4PushCallback(void *ptr)
{
CurrentPage = 4;
}
void page5PuschCallback(void *ptr)
{
CurrentPage = 5;
}
void t1PushCallback(void *ptr)
{
Serial1.print("page1");
Serial1.write(0xff);
Serial1.write(0xff);
}
void t2PushCallback(void *ptr)
{
page2;
}
void t3PushCallback(void *ptr)
{
page3;
}
void t4PushCallback(void *ptr)
{
page4;
}
void t5PushCallback(void *ptr)
{
page5;
}
void setup(){
Serial.begin(9600);
Serial1.begin(9600);
}
void loop(void)
{
delay(30);
if
(CurrentPage == 0) {
}
if(CurrentPage == 1){
uint32_t number;
int Variable = n0.getValue(&number);
Serial.print(";Variable;");
Serial.println( Variable);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(1000);
}
nexLoop(nex_listen_list);
}