Documentation: examples/CompTimer/CompTimer_v0_32.ino Source File

| Documentation For Arduino users

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

- File List
- File Members

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