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