Documentation: examples/CompDualStateButton/CompDualStateButton_v0_32.ino Source File

| Documentation For Arduino users

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

- File List
- File Members

CompDualStateButton_v0_32.ino
1
20 #include "Nextion.h"
21
22 /*
23 * Declare a dual state button object [page id:0,component id:1, component name: "bt0"].
24 */
25 NexDSButton bt0 = NexDSButton(0, 1, "bt0");
26
27 NexText t0 = NexText(0, 2, "t0");
28
29
30 char buffer[100] = {0};
31
32 /*
33 * Register a dual state button object to the touch event list.
34 */
35 NexTouch *nex_listen_list[] =
36 {
37 &bt0,
38 NULL
39 };
40
41 /*
42 * Dual state button component pop callback function.
43 * In this example,the button's text value will plus one every time when it is released.
44 */
45 void bt0PopCallback(void *ptr)
46 {
47 uint32_t dual_state;
48 NexDSButton *btn = (NexDSButton *)ptr;
49 dbSerialPrintln("b0PopCallback");
50 dbSerialPrint("ptr=");
51 dbSerialPrintln((uint32_t)ptr);
52 memset(buffer, 0, sizeof(buffer));
53
54 /* Get the state value of dual state button component . */
55 bt0.getValue(&dual_state);
56 if(dual_state)
57 {
58 t0.setText("HI! OPEN STATE");
59 }
60 else
61 {
62 t0.setText("HI! OFF STATE");
63 }
64 }
65
66 void setup(void)
67 {
68 /* Set the baudrate which is for debug and communicate with Nextion screen. */
69 nexInit();
70
71 /* Register the pop event callback function of the dual state button component. */
72 bt0.attachPop(bt0PopCallback, &bt0);
73
74 dbSerialPrintln("setup done");
75 }
76
77 void loop(void)
78 {
79 /*
80 * When a pop or push event occured every time,
81 * the corresponding component[right page id and component id] in touch event list will be asked.
82 */
83 nexLoop(nex_listen_list);
84 }
85
86
87
88
89
90
91
92
93
94
95
96
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
NexDSButton
NexDSButton component.
Definition: NexDualStateButton.h:36
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
NexDSButton::getValue
bool getValue(uint32_t *number)
Get number attribute of component.
Definition: NexDualStateButton.cpp:23
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