# Course: BUEL456C - Introduction to Raspberry Pi (VTU)
# Wokwi simulation: Potentiometer on GP26 simulates LDR
from machine import ADC, Pin
import time
adc = ADC(Pin(26)) # potentiometer wiper on GP26
BRIGHT = 20000
DARK = 45000
def classify(raw):
if raw < BRIGHT: return "BRIGHT"
elif raw > DARK: return "DARK"
else: return "MEDIUM"
def bar(raw):
filled = int((raw / 65535) * 20)
return "[" + "#" * filled + " " * (20 - filled) + "]"
print("=" * 50)
print(" LDR Simulation | Pico ADC | BUEL456C Wokwi")
print("=" * 50)
while True:
raw = adc.read_u16()
voltage = raw * 3.3 / 65535
pct = (raw / 65535) * 100
print(f" Raw:{raw:6d} | {voltage:.3f}V | "
f"{pct:5.1f}% | {bar(raw)} | {classify(raw)}")
time.sleep(1)Loading
pi-pico
pi-pico