I am building a timing system that has a start, split and finish beams with this I am using a start gate that will drop when the race starts.
when the gate drops it will trip the 1st sensor and will take note of the millis for the"start" then the person will go through the second sensor and that will take note of the millis for the "reaction" and then a final sensor will be passed through and the millis will be noted for the "push" then it will serialPrint them all. After that I will do the math in an excel form (reaction - start will give me the 1st time) then (finish - reaction will give me the 2nd time)
So where I am running into issues is that after the person goes through the 3 timer sensors I have to close the start gate which ends up tripping the first sensor and seems when it gets to the serialPrint section it will use that as the first entry. at first it is hard to notice because I am using very short time frames but when I test it out and go quick through the 1st and 2nd sensors and then take time breaking the last one.... this should give me a small 1st time and large 2nd time but it gives me the opposite so I am assuming that it is because the millis that is being printed in the serial monitor is from when I lift the gate up and break the beam.
so long story short I need to have some sort of way to reset things after the the sensor is tripped when lifting the gate up or a way to use the second millis entry when the sensor is. When the gate is up and locked it is in a HIGH state then when it drops it breaks hte sensor beam and goes in a LOW state (this is when the millis needs to be recorded.... then it stays in a HIGH state until the rider breaks the other 2 beams....... then when you lift the gate it goes from HIGH to LOW (this is millis I want to ignore) then back to HIGH waiting for hte race to start.
I am thinking that the easiest way is to use some sort of switch for the start gate instead of the IR sensor I am using now then it will either be HIGH or LOW and not transfer between the two before it needs to be active.... I am actually waiting on a reed switch but wanted to see if I can get this fixed in the meantime.
//timer
unsigned long start, reaction, push, elapsed;
void setup()
{
Serial.begin(115200);
pinMode(2, INPUT); // start switch
pinMode(3, INPUT); // split sensor
pinMode(4, INPUT); // finish sensor
}
void loop() {
if (digitalRead(2) == LOW )
{
start = millis();
}
if (digitalRead(3) == HIGH)
{
reaction = millis();
// delay(200); // for debounce
}
if (digitalRead(4) == HIGH)
{
push = millis();
delay(500); // for debounce
Serial.print(start);
Serial.print(",");
Serial.print(reaction);
Serial.print(",");
Serial.print(push);
Serial.println();
}
}