Nextion User Manual
For Arduino developers
CompText.ino
How to Use
Show how to use API of class NexText.
Author
Wu Pengfei (email:pengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c)
Date
2015/7/10
#include "Nextion.h"
void t0PopCallback(void *ptr);
void b0PopCallback(void *ptr);
void b1PopCallback(void *ptr);
NexText t0 = NexText(0, 1, "t0");
NexButton b0 = NexButton(0, 2, "b0");
NexButton b1 = NexButton(0, 3, "b1");
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&t0,
&b0,
&b1,
NULL
};
void t0PopCallback(void *ptr)
{
dbSerialPrintln("t0PopCallback");
t0.setText("50");
}
void b0PopCallback(void *ptr)
{
uint16_t len;
uint16_t number;
dbSerialPrintln("b0PopCallback");
memset(buffer, 0, sizeof(buffer));
t0.getText(buffer, sizeof(buffer));
number = atoi(buffer);
number += 1;
memset(buffer, 0, sizeof(buffer));
itoa(number, buffer, 10);
t0.setText(buffer);
}
void b1PopCallback(void *ptr)
{
uint16_t len;
uint16_t number;
dbSerialPrintln("b1PopCallback");
memset(buffer, 0, sizeof(buffer));
t0.getText(buffer, sizeof(buffer));
number = atoi(buffer);
number -= 1;
memset(buffer, 0, sizeof(buffer));
itoa(number, buffer, 10);
t0.setText(buffer);
}
void setup(void)
{
t0.attachPop(t0PopCallback);
b0.attachPop(b0PopCallback);
b1.attachPop(b1PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}