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?
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() {
lastState = digitalRead(photodiodePin);
digitalWrite(ledTX, HIGH); // turn the TX Infrared LED on
Serial.println(digitalRead(photodiodePin)); // Read the pin and display the value
if(digitalRead(photodiodePin) == LOW && lastState == HIGH){
startTime = millis();
lastState = digitalRead(photodiodePin);
}
if(digitalRead(photodiodePin) == HIGH && lastState == LOW){
elapsedTime = millis() - startTime;
Serial.print("Total time: ");
Serial.println(elapsedTime);
lastState = digitalRead(photodiodePin);
}
}
Thank you both,
Shane