import time
import board
import digitalio
import analogio
# Set up LED pin
LED = digitalio.DigitalInOut(board.GP13)
LED.direction = digitalio.Direction.OUTPUT
# Set up LDR pin
ldr = analogio.AnalogIn(board.GP26)
# Function to control LED based on LDR value
def led_control(LED, ldr_value, threshold=30000):
# Light up the LED when it is dark (LDR value is high)
if ldr_value > threshold: # Adjust the threshold as needed
LED.value = True # Turn LED on
else:
LED.value = False # Turn LED off
while True:
# Read the raw ADC value from the LDR
ldr_value = ldr.value
# Print the raw LDR value
print(f"LDR Value: {ldr_value}")
# Control LED based on LDR value
led_control(LED, ldr_value)
time.sleep(1)