# imports
import machine
import math
import RPi.GPIO as GPIO
import time
# Define GPIO pin connected to the LDR
LDR_PIN = 26
# Define GPIO pin connected to the LED
LED_PIN = 28
try:
while True:
# Read the value from the LDR
ldr_value = GPIO.input(LDR_PIN)
# If LDR detects low light intensity (darkness)
if ldr_value == GPIO.LOW:
# Turn on the LED
GPIO.output(LED_PIN, GPIO.HIGH)
print("Darkness detected! LED turned on.")
else:
# Turn off the LED
GPIO.output(LED_PIN, GPIO.LOW)
print("Light detected! LED turned off.")
# Wait for a short duration to avoid continuous checking
time.sleep(0.5)
except KeyboardInterrupt:
# Clean up GPIO on keyboard interrupt
GPIO.cleanup()
if __name__ == '__main__':
setup()
#display_value_test()
while True:
time.sleep(0.5)