I am designing a laser gate timing system to measure the 40 yard dash using some retro reflective sensors for my start and stop. I am having a difficult time trying to figure out the coding for a static start to start the time.
What I mean by static start is if an athletes hand or foots breaks the sensor beam for more than so many second simulating that they are standing still, then when the hand or foot moves out of the way and the sensor beam rejoins the timer starts.
I know very little coding and any help would be appreciated. Don't know if it is a while loop of an if loop, or anything like that.
Doesn't the timing start when the race official fires a gun, waves a flag, changes a light color, says go, etc.? If not, then you don't take into account the athletes reaction time to the "go" command.
You'd have to capture some starts in slow motion and see which part of the body moves first, then perhaps line your laser gate with that.
You could shine one of these across, when the athletes line up the beam is blocked, when they depart the beam is unblocked and the output changes state, turning on an NPN transistor. Connect to input of Arduino with internal pullup resistor. Blocked beam reads as High (NPN is off and output is pulled up), unblocked beam reads as Low (NPN is on and output connects the pullup to Gnd). https://www.mpja.com/Laser-Opto-Interupter-Beam-Type-12mm/productinfo/34836+HD/
I see your logic. There is no reaction time for the athlete, the athlete would "go" when they are ready. In the NFL combine when they do the 40 yard dash, the athlete has their hand on the ground which breaks the beam. Then when the athlete starts his run, the hand is one of the things that moves first. So the beam will rejoin and start the timer.
I just want the timing system to have the athletes hand or foot to remain in place for so many second (like 2 seconds). Once the two seconds is up, the system in now just waiting for the beam to rejoin to start the timer.
millis() runs continuously so you have to capture the start & stop times as variables and then subtract.
Near the beginning you might want a "do nothing" [u]while() loop[/u](inside your main loop) that just sits there doing nothing while the start-beam is broken. ...And, maybe another one before that to wait for the initial beam-break.
The two most important concepts in programming are conditional execution (if statements, etc.) and loops (doing something over-and-over, usually until some condition is reached).
There are 3 kinds of loops in C/C+... while() loops, do-while() loops, and for-loops. A for-loop is useful for a counter if want to run the loop a certain number of times.
Once you understand those two concepts you can start to write useful programs.
The Arduino also usually has a main loop() that runs continuously after setup() until the processor is reset or power-cycled.
I'd suggest using a finite state machine, along the lines of:
switch( stateStartingGate )
{
case WAIT_STATIC:
//wait for beam to be "blocked" for at least 2 seconds
if( start beam is blocked for more than 2 seconds )
{
turn on green LED indicating ready
stateStartingGate = WAIT_LEAVE;
}
break;
case WAIT_LEAVE:
//wait for beam to re-establish, then start timing
if( beam is unblocked )
{
timeStart = millis
turn off green LED
stateStartingGate = WAIT_BLANKING_PERIOD
}
break;
case WAIT_BLANKING_PERIOD:
//if need be: allow runners legs or shoes etc time to pass the
//starting beam before looking for the finish
if( 3-second blanking period has ended )
stateStartingGate = WAIT_FINISH
break;
case WAIT_FINISH:
if( finish beam is blocked OR too much time has elapsed )
{
elapsedTime = millis - timeStart
if valid, display results
//go back and wait again
stateStartingGate = WAIT_STATIC
}
break;
}//switch
I am not very familiar with a finite state machine and how the coding would work. I am hoping to use if and while loops, but ya my programming skills are not that great.
So I made something similar using regular lasers and photoresistors, but it starts the time when laser 1 goes below 300, and then stops the time when laser 2 goes below 300, and the time is displayed on a LCD screen.
So how can I change this code to have the value for laser 1 below 300 for so many seconds, then when the value for laser 1 goes above 300 the timer starts? And then when the value for laser 2 goes below 300 the timer stops and the result is displayed on the LDC.
void loop()
{
elapsed=0;
if (analogRead(LDR1) < 300 ) // When laser 1(LDR1) is blocked time starts. This happens when the value of LDR1 goes below 300.
start = millis(); // saves the beginning
{
while(analogRead(LDR2)<300) //stays in a loop until the value of LDR2 goes below 300.
{
finished = millis(); // saves the finishing time so the final time can be calculated
delay(200);
lcd1.clear();
displayResult(); // see the: void displayResult()
}
displayResult();
}
}