ofey:
Hi,Yes I see it now. Seems to be working now. Do you think it is correct to update 'lastState' in the three places I did?
Not really. That's the current state if you do it at the start of the loop. More like (and note the use of "code" tags) ...
void loop()
{
byte currentState = digitalRead(photodiodePin);
digitalWrite(ledTX, HIGH); // turn the TX Infrared LED on
Serial.println(currentState); // Read the pin and display the value
if(currentState == LOW && lastState == HIGH)
{
startTime = millis();
}
if(currentState == HIGH && lastState == LOW)
{
elapsedTime = millis() - startTime;
Serial.print("Total time: ");
Serial.println(elapsedTime);
}
lastState = currentState;
} // end of loop