Hello all.
I'm trying to display a chronograph on a Nextion monitor to count the "work time" of one machine. However if I have the display command on the Loop statement, the system "freezes" showing the time, and does not do anything else, like listening if a nextion button is pressed... I'm lost in what do to change that... any help?
This is what I have:
#include "Nextion.h"
NexDSButton bt0 = NexDSButton(0, 5, "luz");
NexText choras = NexText(0, 8, "Choras");
NexText cminutos = NexText(0, 9, "Cminutos");
NexText csegundos = NexText(0, 10, "Csegundos");
unsigned long over;
unsigned long timestart;
unsigned long timeend;
long hours = 0; // 3600000 milliseconds in an hour
long minutes = 0; // 60000 milliseconds in a minute
long seconds = 0; // 1000 milliseconds in a second
char buffer_temp[10] = {0};
char buffer_horas[10] = {0};
char buffer_minutos[10] = {0};
uint8_t buffer_second =0;
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&bt0,
&bt1,
NULL
};
// check dual state button and turn on or off one led
void bt0PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt0.getValue(&dual_state);
if(dual_state)
{
digitalWrite(2,HIGH);
}
else
{
digitalWrite(2,LOW);
}
}
// check dual state button and turn on or off one led
void bt1PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt1.getValue(&dual_state);
if(dual_state)
{
digitalWrite(3,HIGH);
}
else
{
digitalWrite(3,LOW);
}
}
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2,LOW);
pinMode(3, OUTPUT);
digitalWrite(3,LOW);
nexInit();
bt0.attachPop(bt0PopCallback, &bt0);
bt1.attachPop(bt1PopCallback, &bt1);
timestart= millis(); // Start chrono
}
void loop() {
nexLoop(nex_listen_list);
displaycrono(); // display chrono (problematic part)
}
void displaycrono() {
timeend = millis() - timestart;
hours=int(timeend/3600000);
over=timeend%3600000;
minutes=int(over/60000);
over=over%60000;
seconds=int(over/1000);
memset(buffer, 0, sizeof(buffer));
memset(buffer_temp, 0, sizeof(buffer_temp));
itoa(seconds, buffer_temp, 10);
if (seconds < 10)
{
strcat(buffer, "0");
}
strcat(buffer, buffer_temp);
if (strcmp(buffer_second, buffer))
{
csegundos.setText(buffer);
}
memset(buffer, 0, sizeof(buffer));
memset(buffer_temp, 0, sizeof(buffer_temp));
itoa(minutes, buffer_temp, 10);
if (minutes < 10)
{
strcat(buffer, "0");
}
strcat(buffer, buffer_temp);
if (strcmp(buffer_minutos, buffer))
{
cminutos.setText(buffer);
}
memset(buffer, 0, sizeof(buffer));
memset(buffer_temp, 0, sizeof(buffer_temp));
itoa(hours, buffer_temp, 10);
if (hours < 10)
{
strcat(buffer, "0");
}
strcat(buffer, buffer_temp);
if (strcmp(buffer_horas, buffer))
{
choras.setText(buffer);
}
}