'''
ESP32analog input converter(analog to digital converter,abbreviationADC)Can be used as32~39foot,
The input voltage is between0V~3.6V、12bit sampling,The quantized value is between0~4095。
ADC.ATTN_11DB:11dB attenuation,Input voltage upper limit3.6V。
ADC.WIDTH_12BIT:12Bit(212,0~4095)
'''
from machine import Pin, ADC
from time import sleep
LDR = ADC(Pin(26, Pin.IN))
LDR.atten(ADC.ATTN_11DB)
led1 = Pin(22, Pin.OUT)
led2 = Pin(19, Pin.OUT)
led3 = Pin(4, Pin.OUT)
while True:
if LDR.read() < 2500:
#led1.value(0)
led1.off()
led2.off()
led3.off()
elif LDR.read() < 3000 :
#led1.value(1)
led1.on()
led2.off()
led3.off()
elif LDR.read() < 3500 :
led1.on()
led2.on()
led3.off()
elif LDR.read() < 4000 :
led1.on()
led2.on()
led3.on()
sleep(0.5)
print(LDR.read())