I'm making a chronograph using two strips of aluminum foil placed 1 foot apart, the idea is to measure the time from when the first strip breaks to when the second strip breaks. sounds simple but I can't seem to get it to work. I set up a test circuit to manually test it by simply disconnecting one wire then the other, but it only gives me a 0 , -2147483648, or -1. Any help I could get would be greatly appreciated.
const int trip1 = 4;
const int trip2 = 5;
int trip1state = 1;
int trip2state = 1;
long timestart =0;
long timestop = 0;
long totaltime = 0;
int fps = 0;
float timeinseconds;
void setup() {
pinMode (trip1,INPUT);
pinMode (trip2,INPUT);
Serial.begin(9600);
}
void loop(){
while (timestop==0){
if (digitalRead(trip1) == LOW){
timestart = micros();
}
if (digitalRead(trip2) == LOW){
timestop = micros();
totaltime = timestart - timestop;
timeinseconds = totaltime / 1000000;
fps = 1/timeinseconds;
Serial.println(fps);
}
}
}