# Source: Electrocredible.com, Language: MicroPython
import utime
from machine import Pin,I2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
button1=Pin(2,Pin.IN,Pin.PULL_UP)
I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16
i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
utime.sleep(1)
lcd.clear()
while True:
a=button1.value()
print(a)
if(a==0):
lcd.move_to(0,0)
lcd.putstr("button ")
lcd.move_to(0,1)
lcd.putstr('pressed ')
if(a==1):
lcd.move_to(0,0)
lcd.putstr("button ")
lcd.move_to(0,1)
lcd.putstr('released')