Using millis() to get elapsed time

Hi Nick,

Thanks that's much better. I am getting some strange characters in the serial monitor. I can't copy and paste them but they are the elapsed times and a backward P with two legs and a dollar sign.

int ledTX = 12; //Receives InfraRed signal
int photodiodePin = 2;              // Photodiode connected to digital pin 2
int lastState;
unsigned long startTime;
unsigned long elapsedTime;
void setup() {                
  Serial.begin(9600);          
  pinMode(ledTX, OUTPUT); 
  pinMode(photodiodePin, INPUT);    // sets the digital pin as input to read photodiode
}
void loop() {
  byte currentState = digitalRead(photodiodePin);
  digitalWrite(ledTX, HIGH);   // turn the TX Infrared LED on
  if(currentState == LOW && lastState == HIGH){
    startTime = millis();
  }
  if(currentState == HIGH && lastState == LOW){
    elapsedTime = millis() - startTime;
    Serial.print(elapsedTime);
    Serial.write(elapsedTime);
  }
  lastState = currentState;
}

I am also trying to send the elapsedTime variable to processing.

Thanks,

Shane