In this note I will keep the work according to the logic of timing based on the radio set Arduino for adults. Timing we need for training. Homemade omega by Lev Ivanov measure time for one skier on the course. In training, this led to a queue at the start, so we did not always install timekeeping. In the formulation of the task it was postulated: at the same time (maximum) three participants could ski on the slalom course and results show at three time indicators. I had to tinker with logic.
Three indicators show the time of the just-finished skier (top) and the previous two (scrolling down at each finish). When the skier (s) is on the track, the colon flashes on the upper indicator, but the time is not running, the result of the previous skier is shown.
Maximum one skier on the course
If only one participant is programmatically allowed on the course, the logic of signal processing “Start” and “Finish” is simple and reliable. Namely: the “Start” button is disabled until the participant has finished, and the “Finish” button is disabled until the participant has started.
Of course, you also need to provide a “cut-off for exceeding the maximum possible time” in case the participant did not finish. So implemented in the omega of Lev Ivanov. If the participant has gone and has not crossed the Finish, then the next one should wait 40 seconds until the start.
Such logic is very easy implemented in Arduino. The fact is that when you press the buttons, a trigger pulse is not generated in Arduino. The board simply polls the corresponding digital input all the time. When the button is pressed, Arduino fixes that the status of according digital input has changed. And since the survey occurs much more often than the time a button is pressed, a series of push start button is fixed. Therefore, a logical prohibition on the next start until the finish button is pressed, immediately leaves in the program only the fact of the first reading of the pressed button. Of course, you can deal with the buttons in different ways, but the logic “only one participant on the track” does everything very easy.
By the way, three indicators with scrolling down (like the scoreboard at the Airport), this is convenient and with the “one participant” logic 🙂
On the course a maximum of three participants
Go to the three participants on the course. So second participant now must not wait until prevous one cross finish line, but can start just as ready. And third one too. From the Finish side, a ban can come only after the start of three participants, acting on the fourth one who wants to start. In addition, this person needs to count the number of participants who are already skiing along the course, and it is much more difficult than, as described in the previous section, to wait for the finish of one participant. In addition, the first three participants “have the right” to start one by one, so the logical ban on the necessary pause will have to be taken. Without such a ban, Arduino can count all three “Start” signals during the first push of a button.
Thus, you immediately have to go to uncomfortable restrictions. The first is a pause between the start of the participants, the second is the maintenance of this pause. At the very least, it is necessary to provide for a “light bulb – You can start,” or/and a sound signal.
There are other difficulties too. I will give a description of the algorithm “as is”.
Constants and variables
The required pause between starts and the LED “can go” is set (with additional forbidding sound signal). If the participant inspite all warnings still go through the starting wicket, his time will not be measured.
Logic control goes through a bunch of “flags” – logical variables. These are “can start” for each of the three participants (participants are numbered A, B, C) and “Participant on the course” (for each of the three participants).
For the storage of the times read from the internal timer Arduino, the following cells are entered: Start time (for each of the three participants) and one finish time (since finishing participant is always “A”, see below).
When the program is started, all flags are cleared (there is no one on the course), except “can start” for participant A.
The same reset (as when the program is started) is performed at any time by pressing the DNF-Reset (Did Not Finished) button. That is, if the participant has left the course, then you need to click on this button, preferably when there are no other participants on the track. After that, the program will again wait for participant A (first). It should be noted that this is a much more important button than the analogue of the “cut-off time” for the case of one participant on the course. With several participants, if one does not finish, the program will assign this finish to the next participant and then everything will “float”, since the start will be taken from one participant, and the finish from the other. I plan to place such a “miracle button” both at the start and in the base unit (about the hardware configuration here: Timing system for Alpine ski based on Arduino. Task formulation).
According to remark of Alexander Mistryukov reworked logic. Now pressing the DNF button is processed exactly as a finish, but without showing the result. If there are already several participants on the course, then you can save the results of those who go for the unfinished ones. That is, pressing the DNF button does not reset all participants, but only the one who was supposed to finish, but did not finish. Just in case, I left “Reset” (as before, resetting all riding participants) by a long press of a button.
In the main loop, the program all the time polls whether the buttons are pressed. About the button DNF-Reset already written. Next, about the “Start” button.
Processing of Starts
With the start button it is more and more complicated, since pressing the button is necessary to spread to participants A, B, C, while participants B or C may not be 🙂 At the same time, to organize a mandatory pause between program starts, you need to carry out actions without pressing buttons, namely calculate whether this pause has passed.
Let’s start with participant A, he does not need to observe any pauses, he starts the very first. Permission to start it is given at program start. When the start button is pressed, the logic is processed: reset the “You can start” checkbox, read the start time from the Arduino timer, check the “Participant A on the course” box and turn off the “You can start” LED.
Participant A has gone to the course, but no one presses the start button, the LED does not light, participant B cannot start. If he starts, that is, he presses the “Start” button (opens the starting gate), nothing will happen, because the “can start participant B” box is not set.
In the main loop, in which the program polls whether the buttons are pressed, the current time is constantly read from the internal Arduino timer. This time is compared with the start time of participant A (who has already gone onto the course) plus the necessary pause. Before comparison, the condition is checked: participant A is on the course, and participant B is not on the course.
As soon as the read time becomes longer, that is, the pause is sustained, the actions take place: the flag “can start participant B” is set and the LED “You can start” lights up.
After this, participant B can start, the button will work. When the Start button is pressed, actions take place: the flag “can start participant B” is cleared, the start time of participant B is read, the flag “Participant B on the course” is turned on and the LED “You can start” is turned off.
Further, in the main cycle, preparations are being made to allow participant C to start, by checking the condition: participant B is skiing, but participant C is not skiing yet, the current time is longer than the time for participant B, plus the necessary pause. As soon as the condition is satisfied, the checkbox “can start participant C” is set and the LED “You can start” lights up.
Participant C can start at a convenient time for him, only so that participants A and B are still on the course. Otherwise, he will cease to be a participant C (more on this below). After the start, the checkbox “can start participant C” is cleared, the start time of participant C is read, the flag “Participant C on the course” is turned on and the LED is turned off. Now it is not extinguished on the necessary pause, but until participant A does not finish, because more than three participants are not allowed on the course.
So, participant A crosses the finish line, the first of the three. It can’t be otherwise 🙂 To trigger the Finish button, you need a condition so that at least someone is skiing along the course (left from the one-participant approach on the track, just in case). Next is a simple processing. Time is read from the internal timer Arduino. The start time of participant A is subtracted from it. This difference (the result of passing the course) after the necessary processing is displayed on the upper indicator. And the time that (if) before was on the upper indicator moves to the middle one, and the time from the middle indicator to the lower one.
According to participants B and C, a shift occurs: the data B is rewritten to A, C to B, and C cells are reset. That is, from this point on mathematically, participant A is approaching the finish line again (just another humanly :)). More precisely, the following data is being rewritten: the start times, the status of the “Participant on the course” and “Can start” checkboxes.
The above algorithm serves, of course, and one participant on the course, and two. And if it comes to this on the Moscow hills, and three participants at the same time. And four is no longer. Honestly, this is impossible, they do not fit on the course 300 meters long 🙂
Here are collected all the notes on the theme “Timing system for Alpine skiing based on Arduino”.