DigiClock Unit

UNIT-Digi-Clock 是一款 2.1 英寸 4 位数码管(7-segment)显示模块。每一位数字都带有小数点,并额外提供一根用于中间冒号点的连线,可用于显示小数与时钟。该模块采用 TM1637 作为驱动 IC,并使用 STM32F030 进行 I2C 通信。I2C 地址可通过 4-bit 拨码开关修改。红色 LED 支持 8 档亮度,并预留了 4 个固定孔位。

支持以下产品:

DigiClockUnit

MicroPython 应用示例

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9from unit import DigiClockUnit
10import time
11
12
13label0 = None
14i2c0 = None
15digiclock_0 = None
16
17
18now = None
19
20
21def setup():
22    global label0, i2c0, digiclock_0, now
23
24    M5.begin()
25    Widgets.fillScreen(0x222222)
26    label0 = Widgets.Label("label0", 99, 97, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu40)
27
28    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
29    digiclock_0 = DigiClockUnit(i2c0, 0x30)
30    now = str((str(((time.localtime())[3])) + str(":"))) + str(((time.localtime())[4]))
31    digiclock_0.set_string(now)
32    label0.setText(str(now))
33
34
35def loop():
36    global label0, i2c0, digiclock_0, now
37    M5.update()
38    if now != (str((str(((time.localtime())[3])) + str(":"))) + str(((time.localtime())[4]))):
39        now = str((str(((time.localtime())[3])) + str(":"))) + str(((time.localtime())[4]))
40        label0.setText(str(now))
41        digiclock_0.set_string(now)
42    digiclock_0.set_raw(1, 2)
43    time.sleep(1)
44    digiclock_0.set_raw(0, 2)
45    time.sleep(1)
46
47
48if __name__ == "__main__":
49    try:
50        setup()
51        while True:
52            loop()
53    except (Exception, KeyboardInterrupt) as e:
54        try:
55            from utility import print_error_msg
56
57            print_error_msg(e)
58        except ImportError:
59            print("please update to latest firmware")

UiFlow2 应用示例

example.png

cores3_digi_clock_example.m5f2

class DigiClockUnit

Constructors

class DigiClockUnit(i2c: I2C, address: int | list | tuple = 0x30)

初始化 DigiClockUnit。

参数:
  • i2c (I2C) – 要使用的 I2C 端口。

  • address (int | list | tuple) – DigiClockUnit 的 I2C 地址。

UIFLOW2:

init.png

Methods

DigiClockUnit.clear() None

清除显示屏。

UIFLOW2:

clear.png

DigiClockUnit.set_brightness(brightness: int) None

设置显示屏的亮度。

参数:

brightness (int) – 显示屏亮度,范围为 0 到 8。

UIFLOW2:

set_brightness.png

DigiClockUnit.set_raw(data: int, index: int) None

将原始数据写入显示屏。

参数:
  • data (int) – 要写入的数据。

  • index (int) – 数据的索引,范围为 0 到 4。

UIFLOW2:

set_raw.png

DigiClockUnit.set_char(char: str, index: int) None

向显示屏写入一个字符。

参数:
  • char (str) – 要写入的字符。

  • index (int) – 字符的索引,范围为 0 到 4。

UIFLOW2:

set_char.png

DigiClockUnit.set_string(string: str) None

将字符串写入显示屏。

参数:

string (str) – 要写入的字符串。

UIFLOW2:

set_string.png

DigiClockUnit.get_fw_version() int

获取 DigiClockUnit 的固件版本。

返回:

固件版本。

UIFLOW2:

get_fw_version.png