Faces Calculator3 模块
Faces Calculator3 是一个计算器键盘模块。它通过回调报告释放的按键编码,默认使用 I2C 地址 0x08。
支持以下产品:
UiFlow2 应用示例
按键事件显示
该示例在 CoreS3 显示屏上报告释放的按键。回调函数会收到释放的按键编码,将其转换为字符并显示。
在 UiFlow2 中打开 faces_calculator3_cores3_example.m5f2 项目。
UiFlow2 代码块:
MicroPython 应用示例
按键事件显示
在主循环中定期调用 FacesCalculator3Module.tick(),轮询新的按键事件。
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
2#
3# SPDX-License-Identifier: MIT
4
5import os, sys, io
6import M5
7from M5 import *
8from module import FacesCalculator3Module
9
10
11title0 = None
12label0 = None
13faces_calculator3_0 = None
14
15
16event_args = None
17
18
19def faces_calculator3_0_key_event(args):
20 global title0, label0, faces_calculator3_0, event_args
21 event_args = chr(args)
22 label0.setText(str((str("Key: ") + str(event_args))))
23
24
25def setup():
26 global title0, label0, faces_calculator3_0, event_args
27
28 M5.begin()
29 Widgets.setRotation(1)
30 Widgets.fillScreen(0x222222)
31 title0 = Widgets.Title(
32 "Faces Calculator3 CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18
33 )
34 label0 = Widgets.Label("label0", 1, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
35
36 faces_calculator3_0 = FacesCalculator3Module(address=0x08)
37 faces_calculator3_0.set_callback(faces_calculator3_0_key_event)
38
39
40def loop():
41 global title0, label0, faces_calculator3_0, event_args
42 M5.update()
43 faces_calculator3_0.tick()
44
45
46if __name__ == "__main__":
47 try:
48 setup()
49 while True:
50 loop()
51 except (Exception, KeyboardInterrupt) as e:
52 try:
53 from utility import print_error_msg
54
55 print_error_msg(e)
56 except ImportError:
57 print("please update to latest firmware")
API参考
- class module.faces.FacesCalculator3Module(address=8)
基类:
_FacesModule创建 Faces Calculator3 Module 对象。
- 参数:
address (int) – I2C 地址,默认为
0x08。
UiFlow2 代码块:

MicroPython 代码块:
from module import FacesCalculator3Module faces_calculator3 = FacesCalculator3Module()
- set_callback(handler)
设置按键事件回调。
回调函数会收到释放的按键编码。传入
None可禁用回调。- 参数:
handler – 接收一个按键编码或
None的可调用对象。- 返回类型:
None
- tick()
轮询一次;有按键事件时调用回调。
UiFlow2 代码块:

MicroPython 代码块:
faces_calculator3.tick()
- 返回类型:
None
- get_device_id()
获取 Faces 模块的设备类型 ID。
- 返回:
设备类型 ID。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
device.get_device_id()
- get_firmware_version()
获取固件版本。
- 返回:
固件版本。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
device.get_firmware_version()
- get_i2c_address()
获取当前 7 位 I2C 地址。
- 返回:
当前 I2C 地址。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
device.get_i2c_address()
- get_uid()
获取 MCU 的 96 位唯一标识符。
- 返回:
12 字节的唯一标识符。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
device.get_uid()
计算器按键常量:
常量 |
值 |
按键 |
|---|---|---|
|
|
退格 |
|
|
回车 |
|
|
全部清除 |
|
|
存储器 |
|
|
百分比 |
|
|
除法 |
|
|
乘法 |
|
|
减法 |
|
|
加法 |
|
|
正负号 |
|
|
等号 |


