Hello,
I'v had a problem all day whit a button in my Nextion 2.4 inch. I only want to increment a variable in case "hour_" when the "but" button is pushed, but on the serial monitor hasn't showed the incremented number.
Could you help me about this problem?
I use:
- The latest version of Arduino 1.8.
- The latest version of nextion editor V0.52
- The ITEADLIB_Arduino_Nextion-master's library
And code that I've used is:
#include <Nextion.h>
#include <Time.h>
#include <TimeLib.h>
#include <SoftwareSerial.h>
int hour_ = 16;
int min_ = 0;
SoftwareSerial nex_com(10, 11); // RX, TX
NexButton b0 = NexButton(3, 3, "b0");
NexNumber n2 = NexNumber(3, 2, "n2");
NexButton b1 = NexButton(0, 5, "but");
NexTouch *nex_listen_list[] =
{
&b0, // Button added
&b1,
NULL // String terminated
} ;
void setup() {
nex_com.begin(9600);
Serial.begin(9600);
delay(500);
nex_com.print("baud=115200");
nex_com.write(0xff);
nex_com.write(0xff);
nex_com.write(0xff);
//
nex_com.end();
nex_com.begin(115200);
setTime(hour_,min_,0,12,4,17);
b0.attachPush(b0PushCallback);
b1.attachPush(b1PushCallback);
}
void loop()
{
delay(10);
nexLoop(nex_listen_list);
Serial.println(hour_);
}
void b0PushCallback(void *ptr)
{
hour_= hour_ - 1;
nex_com.print("n0.val=");
nex_com.print(hour_);
nex_com.write(0xff);
nex_com.write(0xff);
nex_com.write(0xff);
}
void b1PushCallback(void *ptr)
{
hour_ = hour_ + 1;
nex_com.print("n2.val=");
nex_com.print(hour_);
nex_com.write(0xff);
nex_com.write(0xff);
nex_com.write(0xff);
} // End of press event