http://jh7ubc.web.fc2.com/Raspberry_Pi/Raspberry_Pi_Pico/Pi_Pico_AQM0802A.htmlを参考に結線した やはりmpyは事例豊富、mmbasicとかkalumajsは英語サイトだけ
from machine import Pin, I2C
import utime
# I2C
i2c = I2C(
0,
freq=100000,
scl=Pin(17),
sda=Pin(16)
)
addr = 0x3e
buf = bytearray(2)
# コマンド送信
def write_cmd(cmd):
buf[0] = 0x00
buf[1] = cmd
i2c.writeto(addr, buf)
# 文字送信
def write_char(char):
buf[0] = 0x40
buf[1] = char
i2c.writeto(addr, buf)
# 文字列表示
def lcd_print(text):
for c in text:
write_char(ord(c))
# カーソル位置
def LCD_cursor(x, y):
if y == 0:
write_cmd(0x80 + x)
if y == 1:
write_cmd(0xc0 + x)
# LCDクリア
def LCD_clear():
buf[0] = 0x00
buf[1] = 0x01
i2c.writeto(addr, buf)
utime.sleep(0.002)
# LCDホーム
def LCD_home():
buf[0] = 0x00
buf[1] = 0x02
i2c.writeto(addr, buf)
utime.sleep(0.002)
# LCD初期化
def LCD_init():
orders = [
0x38,
0x39,
0x14,
0x73,
0x56,
0x6c,
0x38,
0x0c,
0x01
]
utime.sleep(0.04)
for order in orders:
write_cmd(order)
utime.sleep(0.002)
# =========================
# メイン
# =========================
LCD_init()
LCD_clear()
LCD_home()
lcd_print("JH7UBC")
num = 0
while True:
LCD_cursor(0, 1)
lcd_print(str(num))
num = num + 1
utime.sleep(1)
0 件のコメント:
コメントを投稿