from machine import PWM,Pin,ADC,I2C
import utime
from sh1106 import SH1106_I2C
servo = PWM(Pin(20))
servo.freq(50)
sensor = ADC(0)
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_azul = Pin(18, Pin.OUT)
v = Pin(17, Pin.OUT)
oled.fill(0)
oled.show()
oled.text('EXPLORADORES', 2, 30)
oled.show()
utime.sleep(2)
oled.fill(0)
oled.show()
oled.text('Soy Robot ', 2, 0)
oled.text('Livingstone', 2, 10)
oled.text('Robot GAS ', 2, 20)
oled.text('Equipo Exploradores', 2, 40)
oled.show()
utime.sleep(4)
while True:
GAS = int(sensor.read_u16()/100)
print("VALORES: Sensor gas: ", GAS)
utime.sleep(0.1)
if GAS>=501:
servo.duty_ns(1500000)
v.value(1)
print('DETECTA presencia de gas')
v.value(0)
if GAS>=600:
servo.duty_ns(500000)
v.value(1)
utime.sleep(1)