from machine import Pin, ADC
from time import sleep_ms
led = Pin(0,Pin.OUT,value=0, drive=Pin.DRIVE_0)
sensor = ADC(Pin(2), atten=ADC.ATTN_11DB)
ligado = False
limiar = 30000
offset = 10000
while True:
lido = sensor.read_u16()
if ligado:
if lido < limiar - offset:
led.off()
ligado = False
else:
if lido > limiar:
led.on()
ligado = True
print (lido)
sleep_ms(200)
Loading
aitewinrobot-esp32c3-supermini
aitewinrobot-esp32c3-supermini