im trying to make a chronograph using IR emitters and receivers, I am using analogRead on the receivers and they are set to time when they fall below a certain value, when I open the serial monitor i am not getting an FPS reading that i want here is the code
unsigned long time1, time2;
int val;
int val2;
int firstsens = 4;
int secondsens = 5;
float fps, elap;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (firstsens, INPUT);
pinMode (secondsens, INPUT);
}
void loop()
{
Serial.println("Waiting on next shot");
val = analogRead(firstsens);
val2 = analogRead(secondsens);
while (val > 15);
{
val = analogRead(firstsens);
}
while (val <= 15);
{
time1 = micros();
val = analogRead(firstsens);
}
while (val2 > 15);
{
val2 = analogRead(secondsens);
}
while (val2 <= 15);
{
time2 = micros();
val2 = analogRead(secondsens);
}
elap = time2 - time1;
fps = 999999/elap;
Serial.println(fps);
Serial.println(" FPS ");
}