from machine import Pin, ADC, I2C
from neopixel import NeoPixel
import time
import utime
import ssd1306
#https://wokwi.com/projects/442901490550147073
mq2 = ADC(Pin(34))
mq2.atten(ADC.ATTN_11DB)
I2C_SCL = 22
I2C_SDA = 21
i2c = I2C(0, scl=Pin(I2C_SCL), sda=Pin(I2C_SDA), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
num_leds=4
neo =NeoPixel(Pin(27), num_leds)
def limpiar_pantalla():
oled.fill(0)
oled.show()
def mostrar_texto(texto, x, y):
oled.text(texto, x, y)
oled.show()
def set_color(r,g,b):
for i in range(num_leds):
neo[i]=(r,g,b)
neo.write()
while True:
valorGas= mq2.read()
print("El valor del gas es de ")
print(valorGas)
limpiar_pantalla()
mostrar_texto("Gas: ", 24, 0)
mostrar_texto(str(valorGas), 24, 16)
if(valorGas<900):
set_color(0,255,0)
elif(valorGas>1000 and valorGas<2000):
set_color(255,0,0)
time.sleep(1)
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306