Documentation: examples/CompNumber/CompNumber.ino Source File

| Documentation For Arduino users

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

- File List
- File Members

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