鱼C论坛

 找回密码
 立即注册
查看: 2100|回复: 5

[萌新报道] micro python代码调整

[复制链接]
发表于 2023-12-21 10:44:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
@FishC
micropython ssd1306显示 自动换行
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-12-21 10:47:19 | 显示全部楼层
这段代码增加滚动功能
@FishC
from machine import RTC, SoftI2C, Pin
import ssd1306
import utime

# 配置I2C接口
i2c = SoftI2C(Pin(9), Pin(8))
display = ssd1306.SSD1306_I2C(128, 64, i2c)

# 清空屏幕
display.fill(0)

# 设置绘制的颜色(1=亮,0=暗)
color = 1

# 要显示的文本
text = "This is a long text that needs to be scrolled vertically with automatic line wrapping. "

# 设置每行字符数和行数
characters_per_line = 18
lines = 4

# 分割文本并显示
words = text.split()
current_line = 0
current_text = ""

while True:
    for word in words:
        if len(current_text + word) <= characters_per_line:
            current_text += word + " "
        else:
            display.text(current_text, 0, current_line * 16, color)
            current_line += 1
            current_text = word + " "

    # 显示最后一行文本
    display.text(current_text, 0, current_line * 16, color)
    display.show()
    utime.sleep(2)  # 滚动间隔,可以根据需要调整

    # 清空屏幕
    display.fill(0)
    current_line = 0
    current_text = ""

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-12-21 10:49:15 | 显示全部楼层
FishC 发表于 2023-12-21 10:47
要给这段代码增加滚动功能,可以通过控制文字的显示位置来实现。具体的步骤如下:

1. 创建一个新的变量` ...

运行失败
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-30 03:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表