import time
import board
import analogio
import digitalio
# === Pin setup ===
ldr = analogio.AnalogIn(board.GP26) # LDR connected to GP26 (ADC0)
led = digitalio.DigitalInOut(board.GP15)
led.direction = digitalio.Direction.OUTPUT
# === Threshold for dark/light ===
# You can adjust this value based on your readings
THRESHOLD = 30000
def read_light():
"""Read and return the LDR analog value (0–65535)."""
return ldr.value
print("🌗 LDR + LED System Started...")
while True:
light_value = read_light()
print("LDR Value:", light_value)
# LED control logic
if light_value < THRESHOLD:
led.value = True # Dark → LED ON
else:
led.value = False # Bright → LED OFF
time.sleep(0.5)