A0 input is in the comment section while the HallTach code has it in the Setup portion
It's not the comment section it is the global space where global variables can be declared/initialized.
There are always several ways to do things. The halltach code uses the predefined( in the arduino library) pin name A0 so it doesn't need to be declared. While the nextion code assignes it a name that more clearly indicates what it is doing. Also the nextion code takes advantage of the fact that all pins by default are set as inputs so they do not bother to set them in setup.
If you comment out these two lines:
int sensorPin = A0; // Potentiometer pin to simulate an rpm sensor, for testing
int sensorValue; // Variable to store the value of potentiometer
and add in the variables from the halltach code:
// int sensorPin = A0; // Potentiometer pin to simulate an rpm sensor, for testing
// int sensorValue; // Variable to store the value of potentiometer
int refsig=200;//for converting the analog signal coming from hall sensor to digital through arduino code
int val;//the digital value of the incoming analog signals
int prev_val=0;
unsigned long t,cur_t;//time variables
then comment out these 2 lines:
sensorValue = analogRead(sensorPin); // Read analog pin where the potentiometer is connected
RealRPM = map (sensorValue, 0, 1023, 0, 8000); // Remap pot to simulate an RPM value
and add the halltach code right there:
// sensorValue = analogRead(sensorPin); // Read analog pin where the potentiometer is connected
// RealRPM = map (sensorValue, 0, 1023, 0, 8000); // Remap pot to simulate an RPM value
int sig=analogRead(A0);//read raw value of hall sensor
if(sig>refsig) val=HIGH;//convert it to digital 0,1 form
else val=LOW;
if(prev_val==0 && val==1) {//check for rising edge
cur_t=micros();
RealRPM = (1000000*60/(cur_t-t));//print the rpm
t=micros();
}
prev_val=val;
RealRPM = constrain(RealRPM, 0, 8000); // Constrain the value so it doesn't go below or above the limits
That should do it. It isn't the way I would do it but it follows the style they used. Like I said always lots of different ways to do stuff.