# LDR-Controlled System without ADC (Digital Threshold Trigger)
# Raspberry Pi Pico + Wokwi Simulation
from machine import Pin
from time import sleep
# Pin setup
ldr = Pin(16, Pin.IN) # LDR circuit providing digital HIGH/LOW
led = Pin(15, Pin.OUT) # Simple LED
red = Pin(13, Pin.OUT)
green = Pin(12, Pin.OUT)
blue = Pin(11, Pin.OUT)
motor = Pin(14, Pin.OUT) # Vibration motor (digital control)
# Function to control RGB LED
def set_rgb(r, g, b):
red.value(r)
green.value(g)
blue.value(b)
# Function to display brightness level with secondary colors
def show_brightness_color():
# Fake brightness levels for simulation (simulate multiple thresholds with LDR)
# For now we only simulate digital (0 = dark, 1 = bright), so show mixed color
# This section can be expanded if analog LDR (ADC) is used later
if ldr.value() == 0:
set_rgb(1, 0, 1) # Magenta (low light)
else:
set_rgb(0, 1, 1) # Cyan (bright)
# Main loop
while True:
light_status = ldr.value() # 0 = dark, 1 = bright
print("Light Detected:" if light_status else "Darkness Detected")
if light_status == 0: # Dark
led.value(1)
motor.value(1)
set_rgb(1, 0, 0) # Red
show_brightness_color()
else: # Bright
led.value(0)
motor.value(0)
set_rgb(0, 1, 0) # Green
show_brightness_color()
sleep(0.5)