Drag strip sketch in the works

I am working on a "drag strip" sketch. So far, I have wrote code for one lane only. I have made use of "millis" to capture the time from the start of the race to each sector. I have not put this on a board yet and I am still working out details.

My plan: 1, start the race using a start switch and a staging beam "push buttons for now". 2, Light yellow and then green leds to show start of race. 3, Time each sector and serial print it to the monitor. 4, Reset everything to restart the race. "I may not be done with that". 5, Once 1-4 are working I will add a second lane with separate LEDs and timers.

Have a look at the code and please share any ideas that you would like, Mark

//********************************Time holders*********************
unsigned long starttime = 0;        // will store start time
unsigned long sixty  = 0;           // storage for distance time
unsigned long twohundred = 0;
unsigned long fourhundred = 0;
unsigned long traptime = 0;
unsigned long finish = 0;
const int yellowled = 9;     // the number of the LED pins 
const int greenled = 10;
const int stageled = 11;
const int ledPin =  13;   
const int stagebeampin = 2;  // the numbers of the input pins
const int startpin = 4;
const int sixtypin = 5;
const int twohundredpin = 6;
const int fourhundredpin = 7;
const int finishpin = 8;
// Variables will change:
int start = 0;                  //the start switch status
int greenstate = 0;             //is the green light on?
int beamstate = 0;              //is the beam tripped?
int laneone = 0;                // keeps status of lane
void setup() {
  // set the digital pins as output:
  pinMode(ledPin, OUTPUT); 
  pinMode(yellowled, OUTPUT);
  pinMode(greenled, OUTPUT);
  pinMode(stageled, OUTPUT);
  // set the digital pins as input:

void loop()
  Serial.print ("We are now ready to start the race!");

  start = digitalRead(startpin);                    // read the start switch
  beamstate = digitalRead(stagebeampin);            // read the stagebeam state and store 

  if (beamstate == HIGH & start == HIGH);
  {        // Lets start this race
    greenstate = 1;                                 // read the greenlight state and store

  if (!greenstate || ! beamstate){                  // while greenlight is out or stagebeam is not broken laneone is inactive.  
    laneone = 0;  
    laneone = 1;
    digitalWrite(ledPin, HIGH);

  if(laneone == 1){                         //Begin the race timer
    starttime = millis();

    if (sixtypin){
      sixty = (millis() - starttime);       //Capture 60 foot time

    if (twohundredpin) {
      twohundred = (millis() - starttime);    //Capture 200 meter time
    if (fourhundredpin){
      fourhundred = (millis() - starttime);  //Capture 400 meter time

    if (finishpin){
      finish = (millis() - starttime);       //Capture finish time
      traptime = (finish - fourhundred);       //Set trap time

    Serial.print(" sixty "),(sixty),(" 200 "),(twohundred),(" 400 "),(fourhundred),(" trap "),(traptime),(" total "),(finish);


  // set the LEDS OFF
  digitalWrite(ledPin, LOW);
  //reset greenstate
  greenstate = 0;  

Serial.print ("We are now ready to start the race!");

  start = digitalRead(startpin);                    // read the start switch
  beamstate = digitalRead(stagebeampin);            // read the stagebeam state and store 

  if (beamstate == HIGH & start == HIGH);

Well, I'd probably lose the semicolon on the "if". I'd also probably not want to keep seeing "We are ready to start the race!" printed over and over again (and potentially meaning that I actually missed the start of the race!), so I think instead of an "if", I'd use a "while".

I'm working on same (snowmobiles). Given that it's summer for me I have a while before I have to worry about completing everything, but keep in touch.

The way I designed my code I looked at the race as being in three possible states: pre-stage (verify beam integrity / watch for faults), staging (christmas tree countdown / watch for faults), and racing (record beam breaks / calc timings / display time / etc.).

You need two buttons: one to reset the race back to pre-stage and one to start the christmas tree countdown.

For my "beams" I'm intending to use 38Khz IR with the beamer being a simple voltage regulator, 555 timer, and IR LED while the beam target is a fixed-gain IR receiver (TSOP4038). Unfortunately after I placed my order I realized the receiver is on backorder so I haven't been able to test it out yet :~. I tried using a CdS photoresistor initially but found them to react much too slowly, plus you have to worry about ambient light messing up the readings.

Thanks both of you for the tips and suggestions! I will continue on the project and update the post when I get more to show.

Thanks, Mark

Any updates here?