Hello
i have problem that my arduino code won't detect my nextion button.
here is my arduino code:
#include <Nextion.h> // Include the nextion library (the official one) https://github.com/itead/ITEADLIB_Arduino_Nextion
// Make sure you edit the NexConfig.h file on the library folder to set the correct Serial port for the display.
// By default it's set to Serial, which most arduino boards don't have.
// Change "#define nexSerial Serial" to "#define nexSerial Serial" if you are using arduino uno, nano, etc.
// Declare objects that we are going to read from the display. This includes buttons, sliders, text boxes, etc:
// Format: <type of object> <object name> = <type of object>(<page id>, <object id>, "<object name>");
/* ***** Types of objects:
* NexButton - Button
* NexDSButton - Dual-state Button
* NexHotspot - Hotspot, that is like an invisible button
* NexCheckbox - Checkbox
* NexRadio - "Radio" checkbox, that it's exactly like the checkbox but with a rounded shape
* NexSlider - Slider
* NexGauge - Gauge
* NexProgressBar - Progress Bar
* NexText - Text box
* NexScrolltext - Scroll text box
* NexNumber - Number box
* NexVariable - Variable inside the nextion display
* NexPage - Page touch event
* NexGpio - To use the Expansion Board add-on for Enhanced Nextion displays
* NexRtc - To use the real time clock for Enhanced Nextion displays
* *****
*/
NexText weight1 = NexText(0, 21, "weight1");
NexText weight11 = NexText(1, 11, "weight11");
NexText weight2 = NexText(0, 22, "weight2");
NexText weight21 = NexText(2, 11, "weight21");
NexText weight3 = NexText(0, 23, "weight3");
NexText weight31 = NexText(2, 11, "weight31");
NexText weight4 = NexText(0, 24, "weight4");
NexText weight41 = NexText(4, 11, "weight41");
NexText off11 = NexText(1, 10, "off11"); // Text box added, so we can read it
NexText off1 = NexText(5, 13, "off1"); // Text box added, so we can read it
NexText off2 = NexText(6, 13, "off2"); // Text box added, so we can read it
NexText off3 = NexText(7, 13, "off3"); // Text box added, so we can read it
NexText off4 = NexText(8, 13, "off4"); // Text box added, so we can read it
NexButton enter1 = NexButton(5, 2, "enter1");
NexButton enter2 = NexButton(6, 2, "enter2");
NexButton enter3 = NexButton(7, 2, "enter3");
NexButton enter4 = NexButton(8, 2, "enter4");
char buffer[100] = {0}; // This is needed only if you are going to receive a text from the display. You can remove it otherwise.
// Further on this sketch I do receive text so that's why I created this buffer.
// Declare touch event objects to the touch event list:
// You just need to add the names of the objects that send a touch event.
// Format: &<object name>,
NexTouch *nex_listen_list[] =
{
&enter1, // Button added
&enter2, // Button added
&enter3, // Button added
&enter4, // Button added
NULL // String terminated
}; // End of touch event list
////////////////////////// Touch events:
// Each of the following sections are going to run everytime the touch event happens:
// Is going to run the code inside each section only ones for each touch event.
#define ledPin 13
void enter1_press(void *ptr) // Press event for button b1
{
memset(buffer, 0, sizeof(buffer)); // Clear the buffer, so we can start using it
off1.getText(buffer, sizeof(buffer)); // Read the text on the object t7 and store it on the buffer
off11.setText(buffer);
} // End of press event
void setup() {
nexInit();
// initialize both Serial ports:
// put your setup code here, to run once:
Serial.begin(115200); // Start Serial comunication at baud=9600
digitalWrite(13,LOW); // Turn ON internal LED
// Register the event callback functions of each touch event:
// You need to register press events and release events seperatly.
// Format for press events: <object name>.attachPush(<object name>PushCallback);
// Format for release events: <object name>.attachPop(<object name>PopCallback);
enter1.attachPop(enter1_press, &enter1);
}
void loop()
{
weight1.setText("1000");
weight11.setText("1000");
weight2.setText("2000");
weight21.setText("2000");
weight3.setText("3000");
weight31.setText("3000");
weight4.setText("4000");
weight41.setText("4000");
}
in nextion i turn on touch release event what i am doing wrong? please help