while True:
reading = analog_read(1)
voltage = reading * 3.3/1024
print("Reading=%d\tVoltage=%f"%(reading, voltage))
time.sleep(1)
if reading < 100:
GPIO.output(led,GPIO.HIGH)
print("LED ON")
else :
GPIO.output(led,GPIO.LOW)
print("LED OFF")
-------------------------------------------------------------------------
<결과>
>> 빛을 가리지 않았을 때는 100 이상의 값, Voltage, LED OFF라는 문구가 출력
>> 빛을 가리게 되었을 때는 LED가 켜짐과 동시에 100이하의 값, Voltage, LED ON이라고 출력