I am trying to make an arduino heart beat counter . I looked for some code online and found this code on arduino.cc forum but I couldn't understand working of the the given code .. specifically these few lines of code. I took the code from this forum and i am going to leave a link to the page from where I took this code down below.
The full code is given below:
int sensorValue = 0;
int sensorValue = 0; // variable to store the value coming from the sensor
int count=0;
unsigned long time1=0; // store the initial time
unsigned long time2; // store the current time
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
if(count==0)
{time1=millis();
}
time2=millis();
sensorValue = analogRead(sensorPin);
if(sensorValue>156)
{ increment();
}
if(time2>=time1+10000)
{ counter();
}
}
void increment()
{count++;
while(sensorValue>156)
{Serial.print("Sensor value is greater than .75V\n");
}
}
void counter()
{ count=count*6;
Serial.print("Heart beat is ");
Serial.print(count);
Serial.print(" per min\n");
time1=0;
time2=0;
count=0;
}
The part of the code I'm not able to understand (PS:it is in void loop in the very beginning of void loop):
if(count==0)
{time1=millis();
}
time2=millis();
sensorValue = analogRead(sensorPin);
if(sensorValue>156)
{ increment();
}
if(time2>=time1+10000)
{ counter();
}
if u are not able to understand the code i'm leaving a link to the page:this is the link
i would be highly obliged if anyone could really help me soon. Thank u in advance