| Documentation For Arduino users

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

- File List
- File Members

CompButton_v0_32.ino
1
20 #include "Nextion.h"
21
22 /*
23 * Declare a button object [page id:0,component id:1, component name: "b0"].
24 */
25 NexButton b0 = NexButton(0, 1, "b0");
26
27 char buffer[100] = {0};
28
29 /*
30 * Register a button object to the touch event list.
31 */
32 NexTouch *nex_listen_list[] =
33 {
34 &b0,
35 NULL
36 };
37
38 /*
39 * Button component pop callback function.
40 * In this example,the button's text value will plus one every time when it is released.
41 */
42 void b0PopCallback(void *ptr)
43 {
44 uint16_t len;
45 uint16_t number;
46 NexButton *btn = (NexButton *)ptr;
47 dbSerialPrintln("b0PopCallback");
48 dbSerialPrint("ptr=");
49 dbSerialPrintln((uint32_t)ptr);
50 memset(buffer, 0, sizeof(buffer));
51
52 /* Get the text value of button component [the value is string type]. */
53 btn->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 /* Set the text value of button component [the value is string type]. */
62 btn->setText(buffer);
63 }
64
65 void setup(void)
66 {
67 /* Set the baudrate which is for debug and communicate with Nextion screen. */
68 nexInit();
69
70 /* Register the pop event callback function of the current button component. */
71 b0.attachPop(b0PopCallback, &b0);
72
73 dbSerialPrintln("setup done");
74 }
75
76 void loop(void)
77 {
78 /*
79 * When a pop or push event occured every time,
80 * the corresponding component[right page id and component id] in touch event list will be asked.
81 */
82 nexLoop(nex_listen_list);
83 }
84
85
86
87
88
89
90
91
92
93
94
95
nexLoop
void nexLoop(NexTouch *nex_listen_list[])
Listen touch event and calling callbacks attached before.
Definition: NexHardware.cpp:235
NexButton::getText
uint16_t getText(char *buffer, uint16_t len)
Get text attribute of component.
Definition: NexButton.cpp:23
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
NexButton::setText
bool setText(const char *buffer)
Set text attribute of component.
Definition: NexButton.cpp:33
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