"""
Purpose: read light sensor (analog sensor) input voltage on GP27 (connected to ADC channel 1)
and print the ratio and the voltage value
Modified by: Vivian Phan
Date: 10-29-2025
"""
from picozero import Pot,LED # Import Pot for analog reading (picozero does not have a ligth sensor class)
from time import sleep
# Create a light sensor object for photoresistor on GPIO 27 using Pot class.
light_sensor = Pot(27)
#Assign LED object to GPIO 15
nightlight_led=LED(15)
#LED will turn on when light level is less than 0.3
darkness_threshhold= 0.3
print("Light sensor reading started...")
while True:
#read the light level
light_level=light_sensor.value
#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} ")
if light_level < darkness_threshhold:
# It is dark enough, turn the LED on (like a nightlight)
nightlight_led.on()
print("It's dark! LED is ON.")
else:
# It is bright enough, turn the LED off
nightlight_led.off()
print("It's bright! LED is OFF.")
sleep(0.5) # pause every half a second