This commit is contained in:
Siwat Sirichai 2023-09-30 15:42:44 +07:00
parent 3409ed8fb7
commit 9d96b2b5b3
1438 changed files with 117700 additions and 18 deletions

View file

@ -0,0 +1,95 @@
/**
* @example CompButton.ino
*
* @par How to Use
* This example shows that when the button component on the Nextion screen is released,
* the text of this button will plus one every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
/*
* Declare a button object [page id:0,component id:1, component name: "b0"].
*/
NexButton b0 = NexButton(0, 1, "b0");
char buffer[100] = {0};
/*
* Register a button object to the touch event list.
*/
NexTouch *nex_listen_list[] =
{
&b0,
NULL
};
/*
* Button component pop callback function.
* In this example,the button's text value will plus one every time when it is released.
*/
void b0PopCallback(void *ptr)
{
uint16_t len;
uint16_t number;
NexButton *btn = (NexButton *)ptr;
dbSerialPrintln("b0PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the text value of button component [the value is string type]. */
btn->getText(buffer, sizeof(buffer));
number = atoi(buffer);
number += 1;
memset(buffer, 0, sizeof(buffer));
itoa(number, buffer, 10);
/* Set the text value of button component [the value is string type]. */
btn->setText(buffer);
}
void setup(void)
{
/* Set the baudrate which is for debug and communicate with Nextion screen. */
nexInit();
/* Register the pop event callback function of the current button component. */
b0.attachPop(b0PopCallback, &b0);
dbSerialPrintln("setup done");
}
void loop(void)
{
/*
* When a pop or push event occured every time,
* the corresponding component[right page id and component id] in touch event list will be asked.
*/
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,61 @@
/**
* @example CompCrop.ino
*
* @par How to Use
* This example shows that when the crop component on the Nextion screen is released,
* the image of this component will be changed.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
/*
* Declare a crop object [page id:0,component id:1, component name: "q0"].
*/
NexCrop q0 = NexCrop(0, 1, "q0");
NexTouch *nex_listen_list[] =
{
&q0,
NULL
};
/*
* Crop component pop callback function.
* In this example,the image of current crop component will be changed every time when it is released.
*/
void q0PopCallback(void *ptr)
{
uint32_t number = 0;
dbSerialPrintln("q0PopCallback");
q0.getPic(&number);
number += 1;
number %= 2;
q0.setPic(number);
}
void setup(void)
{
nexInit();
q0.attachPop(q0PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,96 @@
/**
* @example CompDualStateButton.ino
*
* @par How to Use
* This example shows that when the dual state button component on the Nextion screen is released,
* the text of Text component will change one every time.
*
* @author huang xianming (email:<xianming.huang@itead.cc>)
* @date 2015/11/11
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
/*
* Declare a dual state button object [page id:0,component id:1, component name: "bt0"].
*/
NexDSButton bt0 = NexDSButton(0, 1, "bt0");
NexText t0 = NexText(0, 2, "t0");
char buffer[100] = {0};
/*
* Register a dual state button object to the touch event list.
*/
NexTouch *nex_listen_list[] =
{
&bt0,
NULL
};
/*
* Dual state button component pop callback function.
* In this example,the button's text value will plus one every time when it is released.
*/
void bt0PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("b0PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt0.getValue(&dual_state);
if(dual_state)
{
t0.setText("HI! OPEN STATE");
}
else
{
t0.setText("HI! OFF STATE");
}
}
void setup(void)
{
/* Set the baudrate which is for debug and communicate with Nextion screen. */
nexInit();
/* Register the pop event callback function of the dual state button component. */
bt0.attachPop(bt0PopCallback, &bt0);
dbSerialPrintln("setup done");
}
void loop(void)
{
/*
* When a pop or push event occured every time,
* the corresponding component[right page id and component id] in touch event list will be asked.
*/
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,78 @@
/**
* @example CompGauge.ino
*
* @par How to Use
* This example shows that ,when the "btn_up" component on the Nextion screen is released,
* the value of gauge component will plus 5, when the "btn_down" component released,
* the value of gauge component will minus 5 every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexGauge pointer = NexGauge(0, 1, "pointer");
NexButton btn_up = NexButton(0, 2, "btn_up");
NexButton btn_down = NexButton(0, 3, "btn_down");
NexTouch *nex_listen_list[] =
{
&btn_up,
&btn_down,
NULL
};
void buttonUpPopCallback(void *ptr)
{
uint32_t number = 0;
dbSerialPrintln("buttonUpPopCallback");
pointer.getValue(&number);
number += 5;
if (number >= 360)
{
number = 0;
}
pointer.setValue(number);
}
void buttonDownPopCallback(void *ptr)
{
uint32_t number = 0;
dbSerialPrintln("buttonDownPopCallback");
pointer.getValue(&number);
if (number >= 5)
{
number -= 5;
}
pointer.setValue(number);
}
void setup(void)
{
nexInit();
btn_up.attachPop(buttonUpPopCallback);
btn_down.attachPop(buttonDownPopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,65 @@
/**
* @example CompGpio.ino
*
* @par How to Use
* This example shows that In nextion screen displays the current
* IO mouth level change, to show how to use the API.
*
* @author huangxiaoming (email:<xiaoming.huang@itead.cc>)
* @date 2016/12/8
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexGpio gpio;
NexNumber n0 = NexNumber(0,1,"n0");
NexNumber n1 = NexNumber(0,3,"n1");
#define GPIO_PUSH_PORT 1
#define GPIO_PWM_PORT 2
#define GPIO_PUSH_OUTPUT_MODE 2
#define GPIO_PWM_OUT_MODE 3
#define CONTROLS_ID 0 //when the modeel is 1 to be valid
uint32_t pwm_value = 0;
void setup()
{
nexSerial.begin(115200);
gpio.pin_mode(GPIO_PUSH_PORT,GPIO_PUSH_OUTPUT_MODE,CONTROLS_ID);
gpio.pin_mode(GPIO_PWM_PORT,GPIO_PWM_OUT_MODE,CONTROLS_ID);
}
void loop()
{
if(gpio.digital_read(1) == 0)
{
gpio.digital_write(GPIO_PUSH_PORT,HIGH);
n0.setValue(1);
}
else
{
gpio.digital_write(GPIO_PUSH_PORT,LOW);
n0.setValue(0);
}
gpio.analog_write(GPIO_PWM_PORT,pwm_value);
n1.setValue(pwm_value);
if(pwm_value == 100)
{
pwm_value = 0;
}
else
{
pwm_value += 20;
}
delay(1000);
}

View file

@ -0,0 +1,73 @@
/**
* @example CompHotspot.ino
*
* @par How to Use
* This example shows that ,when the hot component on the Nextion screen is pressed or released,
* the debug serial will output the debug information every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexHotspot hot0 = NexHotspot(0, 1, "hot0");
NexHotspot hot1 = NexHotspot(0, 2, "hot1");
NexTouch *nex_listen_list[] =
{
&hot0,
&hot1,
NULL
};
void hot0PushCallback(void *ptr)
{
dbSerialPrintln("hot0PushCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
}
void hot1PushCallback(void *ptr)
{
dbSerialPrintln("hot1PushCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
}
void hot0PopCallback(void *ptr)
{
dbSerialPrintln("hot0PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
}
void hot1PopCallback(void *ptr)
{
dbSerialPrintln("hot1PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
}
void setup(void)
{
nexInit();
hot0.attachPush(hot0PushCallback, &hot0);
hot0.attachPop(hot0PopCallback, &hot0);
hot1.attachPush(hot1PushCallback, &hot1);
hot1.attachPop(hot1PopCallback, &hot1);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,124 @@
/**
* @example CompNumber.ino
*
* @par How to Use
* This example shows that ,when the "+" component on the Nextion screen is released,
* the value of number component will plus 1,when the "-" component released ,the value of
* number component will minus 1 every time.
*
* @author huang xianming (email:<xianming.huang@itead.cc>)
* @date 2015/11/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
void n0PopCallback(void *ptr);
void b0PopCallback(void *ptr);
void b1PopCallback(void *ptr);
/*
* Declare a number object [page id:0,component id:3, component name: "n0"].
*/
NexNumber n0 = NexNumber(0, 3, "n0");
/*
* Declare a button object [page id:0,component id:1, component name: "b0"].
*/
NexButton b0 = NexButton(0, 1, "b0");
/*
* Declare a button object [page id:0,component id:2, component name: "b1"].
*/
NexButton b1 = NexButton(0, 2, "b1");
char buffer[100] = {0};
/*
* Register object n0, b0, b1, to the touch event list.
*/
NexTouch *nex_listen_list[] =
{
&n0,
&b0,
&b1,
NULL
};
/*
* number component pop callback function.
*/
void n0PopCallback(void *ptr)
{
dbSerialPrintln("n0PopCallback");
n0.setValue(50);
}
/*
* Button0 component pop callback function.
* In this example,the value of the number component will plus one every time when button0 is released.
*/
void b0PopCallback(void *ptr)
{
uint32_t number;
dbSerialPrintln("b0PopCallback");
n0.getValue(&number);
number += 1;
n0.setValue(number);
}
/*
* Button1 component pop callback function.
* In this example,the value of the number component will minus one every time when button1 is released.
*/
void b1PopCallback(void *ptr)
{
uint32_t number;
dbSerialPrintln("b1PopCallback");
n0.getValue(&number);
number -= 1;
n0.setValue(number);
}
void setup(void)
{
/* Set the baudrate which is for debug and communicate with Nextion screen. */
nexInit();
/* Register the pop event callback function of the current number component. */
n0.attachPop(n0PopCallback);
/* Register the pop event callback function of the current button0 component. */
b0.attachPop(b0PopCallback);
/* Register the pop event callback function of the current button1 component. */
b1.attachPop(b1PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
/*
* When a pop or push event occured every time,
* the corresponding component[right page id and component id] in touch event list will be asked.
*/
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,75 @@
/**
* @example CompPage.ino
*
* @par How to Use
* Show how to use API of class NexPage.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexPage page0 = NexPage(0, 0, "page0");
NexPage page1 = NexPage(1, 0, "page1");
NexPage page2 = NexPage(2, 0, "page2");
NexPage page3 = NexPage(3, 0, "page3");
NexTouch *nex_listen_list[] =
{
&page0,
&page1,
&page2,
&page3,
NULL
};
void page0PopCallback(void *ptr)
{
dbSerialPrintln("page0PopCallback");
page1.show();
}
void page1PopCallback(void *ptr)
{
dbSerialPrintln("page1PopCallback");
page2.show();
}
void page2PopCallback(void *ptr)
{
dbSerialPrintln("page2PopCallback");
page3.show();
}
void page3PopCallback(void *ptr)
{
dbSerialPrintln("page3PopCallback");
page0.show();
}
void setup(void)
{
nexInit();
dbSerialPrintln("setup begin");
page0.attachPop(page0PopCallback);
page1.attachPop(page1PopCallback);
page2.attachPop(page2PopCallback);
page3.attachPop(page3PopCallback);
dbSerialPrintln("setup end");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,65 @@
/**
* @example CompPicture.ino
*
* @par How to Use
* This example shows that ,when the picture component on the Nextion screen is released,
* the picture of current component will be changed every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
/*
* Declare a picture object [page id:0,component id:1, component name: "p0"].
*/
NexPicture p0 = NexPicture(0, 1, "p0");
NexTouch *nex_listen_list[] =
{
&p0,
NULL
};
void p0PopCallback(void *ptr)
{
uint32_t number = 0;
dbSerialPrintln("p0PopCallback");
p0.getPic(&number);
if (number == 1)
{
number = 2;
}
else
{
number = 1;
}
p0.setPic(number);
}
void setup(void)
{
nexInit();
p0.attachPop(p0PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,78 @@
/**
* @example CompProgressBar.ino
*
* @par How to Use
* This example shows that,when the "btn_up" component on the Nextion screen is released,
* the value of progress bar component will plus 5,when the "btn_down" component released ,the value of
* progress bar component will minus 5 every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexProgressBar j0 = NexProgressBar(0, 3, "j0");
NexButton btn_up = NexButton(0, 1, "btn_up");
NexButton btn_down = NexButton(0, 2, "btn_down");
NexTouch *nex_listen_list[] =
{
&btn_up,
&btn_down,
NULL
};
void buttonUpPopCallback(void *ptr)
{
uint32_t number = 0;
dbSerialPrintln("buttonUpPopCallback");
j0.getValue(&number);
number += 5;
if (number >= 100)
{
number = 100;
}
j0.setValue(number);
}
void buttonDownPopCallback(void *ptr)
{
uint32_t number = 0;
dbSerialPrintln("buttonDownPopCallback");
j0.getValue(&number);
if (number >= 5)
{
number -= 5;
}
j0.setValue(number);
}
void setup(void)
{
nexInit();
btn_up.attachPop(buttonUpPopCallback);
btn_down.attachPop(buttonDownPopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,36 @@
/**
* @example CompRtc.ino
*
* @par How to Use
* This example shows that in nextion screen
* displays the current read the RTC time and show how to use the API.
*
* @author huangxiaoming (email:<xiaoming.huang@itead.cc>)
* @date 2016/12/8
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexText t0 = NexText(0,1,"t0");
NexRtc rtc;
uint32_t time[7] = {2016,11,25,12,34,50};
uint8_t time_buf[30] = {0};
void setup()
{
nexSerial.begin(115200);
rtc.write_rtc_time(time);
}
void loop()
{
rtc.read_rtc_time(time_buf,30);
t0.setText(time_buf);
delay(1000);
}

View file

@ -0,0 +1,54 @@
/**
* @example CompSlider.ino
*
* @par How to Use
* This example shows that ,when the slider component on the Nextion screen is released,
* the text value of text component will be changed every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/11
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
NexText t0 = NexText(0, 2, "t0");
NexSlider h0 = NexSlider(0, 1, "h0");
NexTouch *nex_listen_list[] =
{
&h0,
NULL
};
void h0PopCallback(void *ptr)
{
uint32_t number = 0;
char temp[10] = {0};
dbSerialPrintln("h0PopCallback");
h0.getValue(&number);
utoa(number, temp, 10);
t0.setText(temp);
}
void setup(void)
{
nexInit();
h0.attachPop(h0PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,135 @@
/**
* @example CompText.ino
*
* @par How to Use
* This example shows that ,when the "+" component on the Nextion screen is released,
* the value of text component will plus 1,when the "-" component released ,the value of
* text component will minus 1 every time.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
void t0PopCallback(void *ptr);
void b0PopCallback(void *ptr);
void b1PopCallback(void *ptr);
/*
* Declare a text object [page id:0,component id:1, component name: "t0"].
*/
NexText t0 = NexText(0, 1, "t0");
/*
* Declare a button object [page id:0,component id:2, component name: "b0"].
*/
NexButton b0 = NexButton(0, 2, "b0");
/*
* Declare a button object [page id:0,component id:3, component name: "b1"].
*/
NexButton b1 = NexButton(0, 3, "b1");
char buffer[100] = {0};
/*
* Register object t0, b0, b1, to the touch event list.
*/
NexTouch *nex_listen_list[] =
{
&t0,
&b0,
&b1,
NULL
};
/*
* Text component pop callback function.
*/
void t0PopCallback(void *ptr)
{
dbSerialPrintln("t0PopCallback");
t0.setText("50");
}
/*
* Button0 component pop callback function.
* In this example,the value of the text component will plus one every time when button0 is released.
*/
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);
}
/*
* Button1 component pop callback function.
* In this example,the value of the text component will minus one every time when button1 is released.
*/
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)
{
/* Set the baudrate which is for debug and communicate with Nextion screen. */
nexInit();
/* Register the pop event callback function of the current text component. */
t0.attachPop(t0PopCallback);
/* Register the pop event callback function of the current button0 component. */
b0.attachPop(b0PopCallback);
/* Register the pop event callback function of the current button1 component. */
b1.attachPop(b1PopCallback);
dbSerialPrintln("setup done");
}
void loop(void)
{
/*
* When a pop or push event occured every time,
* the corresponding component[right page id and component id] in touch event list will be asked.
*/
nexLoop(nex_listen_list);
}

View file

@ -0,0 +1,125 @@
/**
* @example CompTimer.ino
*
* @par How to Use
* This example shows that ,when the OFF button component on the Nextion screen is released,
* the timer will opened,the text will show number changed and push the ADDTIME button timer
* cycle value will increase,when push the DECTIME button timer cycle value will reduce.
*
* @author huang xianming (email:<xianming.huang@itead.cc>)
* @date 2015/8/25
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#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);
}

View file

@ -0,0 +1,68 @@
/**
* @example CompWaveform.ino
*
* @par How to Use
* Show how to use API of class NexWaveform.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/11
* @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues
* @convert by Patrick Martin, no other changes made
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "Nextion.h"
#define LEVEL_HIGH (30)
#define LEVEL_LOW (0)
#define CH0_OFFSET (40 - LEVEL_HIGH/2)
#define CH1_OFFSET (CH0_OFFSET + 40 * 1)
#define CH2_OFFSET (CH0_OFFSET + 40 * 2)
#define CH3_OFFSET (CH0_OFFSET + 40 * 3)
NexWaveform s0 = NexWaveform(0, 1, "s0");
static uint8_t ch0_data = LEVEL_LOW;
static uint8_t ch1_data = LEVEL_LOW;
static uint8_t ch2_data = LEVEL_LOW;
static uint8_t ch3_data = LEVEL_LOW;
void setup(void)
{
nexInit();
dbSerialPrintln("setup done");
}
void loop(void)
{
static uint32_t started = 0;
if (millis() - started >= 2000)
{
started = millis();
if (LEVEL_HIGH == ch0_data)
{
ch0_data = LEVEL_LOW;
}
else
{
ch0_data = LEVEL_HIGH;
}
}
ch1_data = ch0_data + random(0, 2);
ch2_data = ch0_data + random(0, 5);
ch3_data = ch0_data + random(0, 8);
s0.addValue(0, CH0_OFFSET + ch0_data);
s0.addValue(1, CH1_OFFSET + ch1_data);
s0.addValue(2, CH2_OFFSET + ch2_data);
s0.addValue(3, CH3_OFFSET + ch3_data);
}

View file

@ -0,0 +1,10 @@
#include "NexUpload.h"
NexUpload nex_download("nex.tft",10,115200);
void setup() {
// put your setup code here, to run once:
nex_download.upload();
}
void loop() {
// put your main code here, to run repeatedly:
}