Using two digital i/o pins a microprocessor can be used to both emit and detect light through a LED. The concept is simple, switch the biasing of the diode for each condition depending on the circuit layout of the diode. Since the LED is a photodiode, sensitive to light that is above the spectrum at which it displays, it can be polled for the current light level it sees.