from machine import Pin, ADC, I2C, PWM
import utime
from sh1106 import SH1106_I2C
servo = PWM(Pin(19))
servo.freq(50)
sensor = ADC(27)
WIDTH = 128
HEIGHT = 64
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
oled = SH1106_I2C(WIDTH, HEIGHT, i2c)
oled.rotate(1)
led_rojo = Pin(18, Pin.OUT)
led_verde = Pin(17, Pin.OUT)
rele1 = Pin(16, Pin.OUT)
oled.fill(0)
oled.show()
oled.text('Equipo ', 2, 0)
oled.text('Exploradores', 2, 10)
oled.show()
utime.sleep(10)
oled.fill(0)
oled.show()
while True:
GAS = int(sensor.read_u16()/110)
print("VALORES: Sensor gas: ", GAS)
utime.sleep(0.1)
if GAS<600 and GAS>500:
servo.duty_ns(500000)
led_verde.value(1)
led_rojo.value(0)
else:
servo.duty_ns(1500000)
led_verde.value(0)
led_rojo.value(0)
print('DETECTA presencia de gas')
utime.sleep(0.1)