import machine
import utime

# Tentukan pin LDR
ldr_pin = machine.ADC(26)  

led_red = machine.Pin(13, machine.Pin.OUT)
led_yellow = machine.Pin(14, machine.Pin.OUT)
led_green = machine.Pin(15, machine.Pin.OUT)

while True:

    ldr_value = ldr_pin.read_u16() 
    ldr_min = 512
    ldr_max = 65007 
    percentage = ((ldr_value - ldr_min) / (ldr_max - ldr_min)) * 100
    
    if percentage <= 40:
        led_red.value(1)  
        led_yellow.value(0)
        led_green.value(0) 
    elif 41 <= percentage <= 70:
        led_red.value(0) 
        led_yellow.value(1) 
        led_green.value(0)  
    else:
        led_red.value(0)  
        led_yellow.value(0) 
        led_green.value(1) 
    print ("persentase : ",percentage,"%")
    print ("ldr value  : ",ldr_value)
    utime.sleep(1)  
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT