| Documentation For Arduino users

- Main Page
- Related Pages
- Modules
- Classes
- Files
- Examples

- File List
- File Members

CompText_v0_32.ino
1
21 #include "Nextion.h"
22
23 void t0PopCallback(void *ptr);
24 void b0PopCallback(void *ptr);
25 void b1PopCallback(void *ptr);
26
27 /*
28 * Declare a text object [page id:0,component id:1, component name: "t0"].
29 */
30 NexText t0 = NexText(0, 1, "t0");
31
32 /*
33 * Declare a button object [page id:0,component id:2, component name: "b0"].
34 */
35 NexButton b0 = NexButton(0, 2, "b0");
36
37 /*
38 * Declare a button object [page id:0,component id:3, component name: "b1"].
39 */
40 NexButton b1 = NexButton(0, 3, "b1");
41
42 char buffer[100] = {0};
43
44 /*
45 * Register object t0, b0, b1, to the touch event list.
46 */
47 NexTouch *nex_listen_list[] =
48 {
49 &t0,
50 &b0,
51 &b1,
52 NULL
53 };
54
55 /*
56 * Text component pop callback function.
57 */
58 void t0PopCallback(void *ptr)
59 {
60 dbSerialPrintln("t0PopCallback");
61 t0.setText("50");
62 }
63
64 /*
65 * Button0 component pop callback function.
66 * In this example,the value of the text component will plus one every time when button0 is released.
67 */
68 void b0PopCallback(void *ptr)
69 {
70 uint16_t len;
71 uint16_t number;
72
73 dbSerialPrintln("b0PopCallback");
74
75 memset(buffer, 0, sizeof(buffer));
76 t0.getText(buffer, sizeof(buffer));
77
78 number = atoi(buffer);
79 number += 1;
80
81 memset(buffer, 0, sizeof(buffer));
82 itoa(number, buffer, 10);
83
84 t0.setText(buffer);
85 }
86
87 /*
88 * Button1 component pop callback function.
89 * In this example,the value of the text component will minus one every time when button1 is released.
90 */
91 void b1PopCallback(void *ptr)
92 {
93 uint16_t len;
94 uint16_t number;
95
96 dbSerialPrintln("b1PopCallback");
97
98 memset(buffer, 0, sizeof(buffer));
99 t0.getText(buffer, sizeof(buffer));
100
101 number = atoi(buffer);
102 number -= 1;
103
104 memset(buffer, 0, sizeof(buffer));
105 itoa(number, buffer, 10);
106
107 t0.setText(buffer);
108 }
109
110 void setup(void)
111 {
112 /* Set the baudrate which is for debug and communicate with Nextion screen. */
113 nexInit();
114
115 /* Register the pop event callback function of the current text component. */
116 t0.attachPop(t0PopCallback);
117
118 /* Register the pop event callback function of the current button0 component. */
119 b0.attachPop(b0PopCallback);
120
121 /* Register the pop event callback function of the current button1 component. */
122 b1.attachPop(b1PopCallback);
123
124 dbSerialPrintln("setup done");
125 }
126
127 void loop(void)
128 {
129 /*
130 * When a pop or push event occured every time,
131 * the corresponding component[right page id and component id] in touch event list will be asked.
132 */
133 nexLoop(nex_listen_list);
134 }
135
nexLoop
void nexLoop(NexTouch *nex_listen_list[])
Listen touch event and calling callbacks attached before.
Definition: NexHardware.cpp:235
NexText::setText
bool setText(const char *buffer)
Set text attribute of component.
Definition: NexText.cpp:32
NexTouch::attachPop
void attachPop(NexTouchEventCb pop, void *ptr=NULL)
Attach an callback function of pop touch event.
Definition: NexTouch.cpp:39
nexInit
bool nexInit(void)
Init Nextion.
Definition: NexHardware.cpp:220
NexButton
NexButton component.
Definition: NexButton.h:35
NexText::getText
uint16_t getText(char *buffer, uint16_t len)
Get text attribute of component.
Definition: NexText.cpp:22
Nextion.h
The header file including all other header files provided by this library.
NexTouch
Father class of the components with touch events.
Definition: NexTouch.h:53
NexText
NexText component.
Definition: NexText.h:30