"""
Purpose: read light sensor (analog sensor) input voltage on GP27 (connected to ADC channel 1)
and print the ratio and the voltage value
By: Prof. Keyvani
Date: 10-29-2025
"""
from picozero import Pot # Import Pot for analog reading (picozero does not have a ligth sensor class)
from time import sleep
from picozero import LED
# Create a light sensor object for photoresistor on GPIO 27 using Pot class.
light_sensor = Pot(27)
led=LED(15)
print("Light sensor reading started...")
while True:
if light_sensor.value < 0.7:
led.on()
else:
led.off()
#prints the ratio and the voltage from the analog pin (GP27)
print(f"Light level Ratio: {light_sensor.value:.2f}, voltage:{light_sensor.voltage:.2f} ")
sleep(0.5) # pause every half a second