Using millis() to get elapsed time

  lastState = photodiodePin;

Why are you setting a state variable to a pin number?