Nextion User Manual
For Arduino developers
CompButton.ino
1 
17 #include "Nextion.h"
18 
19 NexButton b0 = NexButton(0, 1, "b0");
20 
21 char buffer[100] = {0};
22 
23 NexTouch *nex_listen_list[] =
24 {
25  &b0,
26  NULL
27 };
28 
29 void b0PopCallback(void *ptr)
30 {
31  uint16_t len;
32  uint16_t number;
33  NexButton *btn = (NexButton *)ptr;
34  dbSerialPrintln("b0PopCallback");
35  dbSerialPrint("ptr=");
36  dbSerialPrintln((uint32_t)ptr);
37  memset(buffer, 0, sizeof(buffer));
38  btn->getText(buffer, sizeof(buffer));
39 
40  number = atoi(buffer);
41  number += 1;
42 
43  memset(buffer, 0, sizeof(buffer));
44  itoa(number, buffer, 10);
45 
46  btn->setText(buffer);
47 }
48 
49 void setup(void)
50 {
51  nexInit();
52  b0.attachPop(b0PopCallback, &b0);
53  dbSerialPrintln("setup done");
54 }
55 
56 void loop(void)
57 {
58  nexLoop(nex_listen_list);
59 }
void nexLoop(NexTouch *nex_listen_list[])
Listen touch event and calling callbacks attached before.
uint16_t getText(char *buffer, uint16_t len)
Get text attribute of component.
Definition: NexButton.cpp:23
void attachPop(NexTouchEventCb pop, void *ptr=NULL)
Attach an callback function of pop touch event.
Definition: NexTouch.cpp:39
bool nexInit(void)
Init Nextion.
NexButton component.
Definition: NexButton.h:35
bool setText(const char *buffer)
Set text attribute of component.
Definition: NexButton.cpp:33
The header file including all other header files provided by this library.
Father class of the components with touch events.
Definition: NexTouch.h:53