from machine import Pin, I2C
import utime
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
# I2C設定 (GP0=SDA, GP1=SCL)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
# LCDのI2Cアドレスを確認して設定 (0x27 や 0x3F が多い)
I2C_ADDR = 0x27
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16) # 2行16文字LCD
# ボタン設定 (GP14, プルアップ有効)
button = Pin(14, Pin.IN, Pin.PULL_UP)
while True:
if button.value() == 0: # 押されたら 0
lcd.clear()
lcd.putstr("Hello")
print("Button pressed!")
utime.sleep(0.5) # チャタリング対策 & 連続押し防止
Loading
pi-pico-w
pi-pico-w