CompTimer_v0_32.ino
#include "Nextion.h"
NexButton b0 = NexButton(0, 2, "b0");
NexButton b1 = NexButton(0, 5, "b1");
NexButton b2 = NexButton(0, 6, "b2");
NexText t0 = NexText(0, 3, "t0");
NexText t1 = NexText(0, 4, "t1");
NexTimer tm0 = NexTimer(0, 1, "tm0");
char buffer[100] = {0};
uint32_t number_timer = 0;
uint32_t number_enable = 0;
uint32_t number_cycle = 100;
NexTouch *nex_listen_list[] =
{
&b0,
&b1,
&b2,
&t0,
&t1,
&tm0,
NULL
};
/*
* Button component pop callback function.
* In this example,the button can open the timer when it is released.
*/
void b0PopCallback(void *ptr)
{
if(number_enable == 1)
{
tm0.enable();
number_enable = 0;
b0.setText("ON");
}
else if (number_enable ==0)
{
tm0.disable();
number_enable =1;
b0.setText("OFF");
}
}
/*
* Button component pop callback function.
* In this example,the timer's cycle value will increase when it is released.
*/
void b1PopCallback(void *ptr)
{
tm0.getCycle(&number_cycle);
number_cycle = number_cycle + 100;
tm0.setCycle(number_cycle);
memset(buffer, 0, sizeof(buffer));
itoa(number_cycle, buffer, 10);
t1.setText(buffer);
}
/*
* Button component pop callback function.
* In this example,the timer's cycle value will reduce when it is released.
*/
void b2PopCallback(void *ptr)
{
tm0.getCycle(&number_cycle);
if (number_cycle >100)
{
number_cycle = number_cycle - 100;
}
tm0.setCycle(number_cycle);
memset(buffer, 0, sizeof(buffer));
itoa(number_cycle, buffer, 10);
t1.setText(buffer);
}
/*
* The timer respond function
* In this example,the timer will respond when set cycle time done and puls one for a variable.
*/
void tm0TimerCallback(void *ptr)
{
number_timer++;
memset(buffer, 0, sizeof(buffer));
itoa(number_timer, buffer, 10);
t0.setText(buffer);
}
void setup(void)
{
nexInit();
b0.attachPop(b0PopCallback);
tm0.attachTimer(tm0TimerCallback);
b1.attachPop(b1PopCallback);
b2.attachPop(b2PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}
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