Nextion User Manual
For Arduino developers
CompText.ino
1 
17 #include "Nextion.h"
18 
19 void t0PopCallback(void *ptr);
20 void b0PopCallback(void *ptr);
21 void b1PopCallback(void *ptr);
22 
23 NexText t0 = NexText(0, 1, "t0");
24 NexButton b0 = NexButton(0, 2, "b0");
25 NexButton b1 = NexButton(0, 3, "b1");
26 
27 char buffer[100] = {0};
28 
29 NexTouch *nex_listen_list[] =
30 {
31  &t0,
32  &b0,
33  &b1,
34  NULL
35 };
36 
37 void t0PopCallback(void *ptr)
38 {
39  dbSerialPrintln("t0PopCallback");
40  t0.setText("50");
41 }
42 
43 void b0PopCallback(void *ptr)
44 {
45  uint16_t len;
46  uint16_t number;
47 
48  dbSerialPrintln("b0PopCallback");
49 
50  memset(buffer, 0, sizeof(buffer));
51  t0.getText(buffer, sizeof(buffer));
52 
53  number = atoi(buffer);
54  number += 1;
55 
56  memset(buffer, 0, sizeof(buffer));
57  itoa(number, buffer, 10);
58 
59  t0.setText(buffer);
60 }
61 
62 void b1PopCallback(void *ptr)
63 {
64  uint16_t len;
65  uint16_t number;
66 
67  dbSerialPrintln("b1PopCallback");
68 
69  memset(buffer, 0, sizeof(buffer));
70  t0.getText(buffer, sizeof(buffer));
71 
72  number = atoi(buffer);
73  number -= 1;
74 
75  memset(buffer, 0, sizeof(buffer));
76  itoa(number, buffer, 10);
77 
78  t0.setText(buffer);
79 }
80 
81 void setup(void)
82 {
83  nexInit();
84  t0.attachPop(t0PopCallback);
85  b0.attachPop(b0PopCallback);
86  b1.attachPop(b1PopCallback);
87  dbSerialPrintln("setup done");
88 }
89 
90 void loop(void)
91 {
92  nexLoop(nex_listen_list);
93 }
94 
void nexLoop(NexTouch *nex_listen_list[])
Listen touch event and calling callbacks attached before.
bool setText(const char *buffer)
Set text attribute of component.
Definition: NexText.cpp:32
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
uint16_t getText(char *buffer, uint16_t len)
Get text attribute of component.
Definition: NexText.cpp:22
The header file including all other header files provided by this library.
Father class of the components with touch events.
Definition: NexTouch.h:53
NexText component.
Definition: NexText.h:30