这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 继续把玩ESP32-S3ReverseTFTFeatherbyAdafruit(

共1条 1/1 1 跳转至页

继续把玩ESP32-S3ReverseTFTFeatherbyAdafruit(三)

专家
2026-10-10 09:26:08     打赏

接上次的帖子,

https://forum.eepw.com.cn/thread/401710/1

闲来无事,先做个三行的数据动态显示

简单配置后,效果如下:

import board

import displayio
import time
import rtc
import random
import terminalio
from adafruit_display_text import label

display = board.DISPLAY
WIDTH = display.width    # 240
HEIGHT = display.height  # 135

# ========== 设置 RTC 时间(手动,可改成你的当前时间) ==========
rtc.RTC().datetime = time.struct_time((2026, 10, 9, 22, 45, 0, 4, -1, -1))

# ========== 画布(纯背景) ==========
group = displayio.Group()
bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
palette = displayio.Palette(1)
palette[0] = 0x000000   # 背景(黑)
tile = displayio.TileGrid(bitmap, pixel_shader=palette)
group.append(tile)

text_label1 = label.Label(
    terminalio.FONT,
    text="test result" ,
    color=0x00ff00,
    scale=2,
)
#text_label1.anchor_point = (0.5, 0.5)
text_label1.anchored_position = (60, 10)
text_label1.anchor_point = (0.0, 0.0)
group.append(text_label1)

# ========== 第一行:HI EEPW! + 计数 ==========
counter = 0.01
text_label1 = label.Label(
    terminalio.FONT,
    text="HI EEPW! %.2f" % counter,
    color=0x00ff00,
    scale=2,
)
text_label1.anchored_position = (10, 40)
text_label1.anchor_point = (0.0, 0.0)
group.append(text_label1)

# ========== 第二行:时间 ==========
time_label = label.Label(
    terminalio.FONT,
    text="",
    color=0xFFFF00,      # 黄色
    scale=2,
)
time_label.anchored_position = (10, 75)
time_label.anchor_point = (0.0, 0.0)
group.append(time_label)

# ========== 第三行:10 个随机两位小数,随机显示其中一个 ==========
# 生成包含 10 个随机两位小数的数组
num_array = [round(random.uniform(0, 100), 2) for _ in range(10)]

z_label = label.Label(
    terminalio.FONT,
    text="",
    color=0x00FFFF,      # 青色,可自行改色
    scale=2,
)
z_label.anchored_position = (10, 110)
z_label.anchor_point = (0.0, 0.0)
group.append(z_label)

def update_z():
    """从数组中随机取一个数,前面加 Z: 显示"""
    z_label.text = "Z: %.2f" % random.choice(num_array)

# 首次显示
update_z()

display.root_group = group

# ========== 数值计时 ==========
last_count_time = time.monotonic()
last_second = -1

while True:
    now = time.monotonic()

    # 1) 每秒计数 +1
    if now - last_count_time >= 1.0:
        counter += 1
        last_count_time = now
        text_label1.text = "X:%.2f" % counter

    # 2) 每秒刷新时间
    t = time.localtime()
    if t.tm_sec != last_second:
        last_second = t.tm_sec
        time_label.text = "TIME:%02d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
        update_z()

    display.refresh()
    time.sleep(0.01)

效果为数字1s变换一次,这个时间是开机固定写入。这个应该是连接wifi,连接一个ntp服务器获取时间比较准。下一篇完成wifi的连接。

图片.png





关键词: 继续     把玩     ESP32-S3ReverseTFTF    

共1条 1/1 1 跳转至页

回复

匿名不能发帖!请先 [ 登陆 注册 ]