from machine import Pin, ADC
import utime
r = Pin(14, Pin.OUT)
g = Pin(13, Pin.OUT)
b = Pin(12, Pin.OUT)
gas = ADC(26)
while True:
lecturas = gas.read_u16()
print(lecturas)
if lecturas > 50000:
r.value(1)
g.value(0)
b.value(0) # Azul
elif lecturas > 30000:
r.value(0)
g.value(1)
b.value(0)
else:
r.value(0) # Apagado (lecturas menores a 10000)
g.value(0)
b.value(0)
utime.sleep(0.1)
"""
Estructura elif: Ahora las condiciones son exclusivas.
Si entra en una, no ejecuta las demás,
evitando que el LED parpadee o muestre
colores incorrectos.
"""