Documentation
For Arduino users
CompText.ino
1 
19 #include "Nextion.h"
20 
21 void t0PopCallback(void *ptr);
22 void b0PopCallback(void *ptr);
23 void b1PopCallback(void *ptr);
24 
25 NexText t0 = NexText(0, 1, "t0");
26 NexButton b0 = NexButton(0, 2, "b0");
27 NexButton b1 = NexButton(0, 3, "b1");
28 
29 char buffer[100] = {0};
30 
31 NexTouch *nex_listen_list[] =
32 {
33  &t0,
34  &b0,
35  &b1,
36  NULL
37 };
38 
39 void t0PopCallback(void *ptr)
40 {
41  dbSerialPrintln("t0PopCallback");
42  t0.setText("50");
43 }
44 
45 void b0PopCallback(void *ptr)
46 {
47  uint16_t len;
48  uint16_t number;
49 
50  dbSerialPrintln("b0PopCallback");
51 
52  memset(buffer, 0, sizeof(buffer));
53  t0.getText(buffer, sizeof(buffer));
54 
55  number = atoi(buffer);
56  number += 1;
57 
58  memset(buffer, 0, sizeof(buffer));
59  itoa(number, buffer, 10);
60 
61  t0.setText(buffer);
62 }
63 
64 void b1PopCallback(void *ptr)
65 {
66  uint16_t len;
67  uint16_t number;
68 
69  dbSerialPrintln("b1PopCallback");
70 
71  memset(buffer, 0, sizeof(buffer));
72  t0.getText(buffer, sizeof(buffer));
73 
74  number = atoi(buffer);
75  number -= 1;
76 
77  memset(buffer, 0, sizeof(buffer));
78  itoa(number, buffer, 10);
79 
80  t0.setText(buffer);
81 }
82 
83 void setup(void)
84 {
85  nexInit();
86  t0.attachPop(t0PopCallback);
87  b0.attachPop(b0PopCallback);
88  b1.attachPop(b1PopCallback);
89  dbSerialPrintln("setup done");
90 }
91 
92 void loop(void)
93 {
94  nexLoop(nex_listen_list);
95 }
96 
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