Person counter using IR sensor and connected with nextion display

Hello ,

I am new to this programming and trying build an application using IR sensor in UNO which detects and count up the number.
I am using the Nextion display to display the counter value.
This is done. My real challenge start from here
In the HMI i have 3 buttons and 1 Number display.3buttons are up,down,reset.Up will increase the counter by addng 1to the number in number display, similarly down will substract 1 & reset will set it to 0.
My code is not able excute the button function. Pl look into the code and if you find anything is wrong pl point out.

Thanks

Code

#include "Nextion.h"
#include "Softwareserial.h"
SoftwareSerial HMISerial(10, 11);
NexNumber t1 = NexNumber(0, 3, "n0");
int irPin = 7;
int count = 0;
boolean state = true;
NexButton up = NexButton (0,6,"b1");
NexButton down = NexButton (0,5, "b0");
NexButton Reset = NexButton (0,7,"b2");
NexTouch *nex_listen_list =
{
&up,
&down,
&Reset,
NULL
};
void upPushCallback(void *ptr)
{
count = count + 1;

Serial.print("n0.val=");
Serial.print(count);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void downPushCallback(void *ptr)
{
count = count - 1;

Serial.print("n0.val=");
Serial.print(count);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void ResetPushCallback(void *ptr)
{
count = 0;

Serial.print("n0.val=");
Serial.print(count);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

void setup() {
Serial.begin(9600);
up.attachPush(upPushCallback, &up);
down.attachPush(downPushCallback, &down);
Reset.attachPush(ResetPushCallback, &Reset);
}
void loop() {
nexLoop(nex_listen_list);

if (!digitalRead(irPin) && state ) {
count++;
state = false;
Serial.print("n0.val=");
Serial.print(count);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(100);
}

if (digitalRead(irPin)) {
state = true;
delay(100);
}

}

Hello,
If you look at my tutorial Using Nextion Displays with Arduino there is an example very similar to what you are trying to do. Note my methods do not use the Nextion libraries. The tutorial is at the top of the Display section of the forum.

can you put this code instead on the void upPushCallback(void *ptr) function

t1.getValue(&count);
count++;
t1.setValue(number);

can you put this code instead on the void upPushCallback(void *ptr) function

They are called functions, void refers to the type of variable the function returns, with void meaning it doesn't return anything.

Sorry for the confusion; I meant, replace the following function:

void upPushCallback(void *ptr)
{
count = count + 1;

Serial.print(“n0.val=”);
Serial.print(count);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}

By

void upPushCallback(void *ptr) {

t1.getValue(&count);
count++;
t1.setValue(count);

}

Sorry, I don't know, that's Nextion library stuff, which I no nothing about. Maybe someone else can help.

Try it, if it works then you can, if it doesn't then you can't. You won't break anything by trying.

Thanks guys for your support, Perry your tutorial is awsome, It actually helped me.