Documentation: examples/CompNumber/CompNumber_v0_32.ino Source File

| Documentation For Arduino users

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

- File List
- File Members

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