# 导入模块
from machine import I2C, Pin
import ssd1306
import time
# 定义引脚
i2c = I2C(0, scl=Pin(32), sda=Pin(33), freq=400000)
btn = Pin(18, Pin.IN, Pin.PULL_UP)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
x, y = 0, 0
status = 0
# 显示hello world
oled.fill(0)
oled.text("Hello, World!", x, y)
oled.show()
# 按下按键,字符串向下移动
while True:
if btn.value() == 0:
time.sleep_ms(10)
if btn.value() == 0 and status == 0:
y += 10
oled.fill(0)
oled.text("Hello, World!", x, y)
oled.show()
if y >= 50:
y = 0
oled.show()
status = 1
else:
status = 0