| Documentation For Arduino users

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

- File List
- File Members

CompTimer.ino
1
19 #include "Nextion.h"
20
21 NexButton b0 = NexButton(0, 2, "b0");
22 NexButton b1 = NexButton(0, 5, "b1");
23 NexButton b2 = NexButton(0, 6, "b2");
24 NexText t0 = NexText(0, 3, "t0");
25 NexText t1 = NexText(0, 4, "t1");
26 NexTimer tm0 = NexTimer(0, 1, "tm0");
27
28
29 char buffer[100] = {0};
30 uint32_t number_timer = 0;
31 uint32_t number_enable = 0;
32 uint32_t number_cycle = 100;
33
34
35
36 NexTouch *nex_listen_list[] =
37 {
38 &b0,
39 &b1,
40 &b2,
41 &t0,
42 &t1,
43 &tm0,
44 NULL
45 };
46 /*
47 * Button component pop callback function.
48 * In this example,the button can open the timer when it is released.
49 */
50 void b0PopCallback(void *ptr)
51 {
52 if(number_enable == 1)
53 {
54 tm0.enable();
55 number_enable = 0;
56 b0.setText("ON");
57 }
58 else if (number_enable ==0)
59 {
60 tm0.disable();
61 number_enable =1;
62 b0.setText("OFF");
63 }
64 }
65 /*
66 * Button component pop callback function.
67 * In this example,the timer's cycle value will increase when it is released.
68 */
69 void b1PopCallback(void *ptr)
70 {
71 tm0.getCycle(&number_cycle);
72 number_cycle = number_cycle + 100;
73 tm0.setCycle(number_cycle);
74 memset(buffer, 0, sizeof(buffer));
75 itoa(number_cycle, buffer, 10);
76 t1.setText(buffer);
77 }
78
79 /*
80 * Button component pop callback function.
81 * In this example,the timer's cycle value will reduce when it is released.
82 */
83
84 void b2PopCallback(void *ptr)
85 {
86 tm0.getCycle(&number_cycle);
87 if (number_cycle >100)
88 {
89 number_cycle = number_cycle - 100;
90 }
91 tm0.setCycle(number_cycle);
92 memset(buffer, 0, sizeof(buffer));
93 itoa(number_cycle, buffer, 10);
94 t1.setText(buffer);
95 }
96
97 /*
98 * The timer respond function
99 * In this example,the timer will respond when set cycle time done and puls one for a variable.
100 */
101
102 void tm0TimerCallback(void *ptr)
103 {
104 number_timer++;
105 memset(buffer, 0, sizeof(buffer));
106 itoa(number_timer, buffer, 10);
107 t0.setText(buffer);
108 }
109 void setup(void)
110 {
111 nexInit();
112 b0.attachPop(b0PopCallback);
113 tm0.attachTimer(tm0TimerCallback);
114 b1.attachPop(b1PopCallback);
115 b2.attachPop(b2PopCallback);
116 dbSerialPrintln("setup done");
117 }
118
119 void loop(void)
120 {
121 nexLoop(nex_listen_list);
122 }
123
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
NexTimer::enable
bool enable(void)
contorl timer enable.
Definition: NexTimer.cpp:60
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
NexTimer::getCycle
bool getCycle(uint32_t *number)
Get the value of timer cycle val.
Definition: NexTimer.cpp:33
Nextion.h
The header file including all other header files provided by this library.
NexTimer::setCycle
bool setCycle(uint32_t number)
Set the value of timer cycle val.
Definition: NexTimer.cpp:42
NexTimer
NexTimer component.
Definition: NexTimer.h:34
NexTimer::attachTimer
void attachTimer(NexTouchEventCb timer, void *ptr=NULL)
Attach an callback function of timer respond event.
Definition: NexTimer.cpp:23
NexTouch
Father class of the components with touch events.
Definition: NexTouch.h:53
NexTimer::disable
bool disable(void)
contorl timer disable.
Definition: NexTimer.cpp:73
NexText
NexText component.
Definition: NexText.h:30