from time import sleep_ms, ticks_ms from machine import I2C, Pin from i2c_lcd import I2cLcd DEFAULT_I2C_ADDR = 0x27 i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) from machine import Pin import time gas = Pin(23, Pin.IN, Pin.PULL_UP) while True: gasVal = gas.value() # Reads the value of button 1 print("gas =",gasVal) #Print it out in the shell lcd.move_to(1, 1) lcd.putstr('val: {}'.format(gasVal)) if(gasVal == 1): #lcd.clear() lcd.move_to(1, 0) lcd.putstr('Safety ') else: lcd.move_to(1, 0) lcd.putstr('dangerous') time.sleep(0.1) #delay 0.1s