ToF Hat
以下产品受支持:
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 hat import ToFHat 10 11 12label0 = None 13i2c0 = None 14hat_tof_0 = None 15 16 17def setup(): 18 global label0, i2c0, hat_tof_0 19 20 M5.begin() 21 label0 = Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 22 23 i2c0 = I2C(0, scl=Pin(26), sda=Pin(0), freq=100000) 24 hat_tof_0 = ToFHat(i2c0) 25 26 27def loop(): 28 global label0, i2c0, hat_tof_0 29 M5.update() 30 label0.setText(str((str((hat_tof_0.get_range())) + str("mm")))) 31 32 33if __name__ == "__main__": 34 try: 35 setup() 36 while True: 37 loop() 38 except (Exception, KeyboardInterrupt) as e: 39 try: 40 from utility import print_error_msg 41 42 print_error_msg(e) 43 except ImportError: 44 print("please update to latest firmware")
UiFlow2 应用示例:
class ToFHat
Constructors
- class ToFHat(i2c: I2C, address: int = 0x29, io_timeout_ms: int = 0)
创建 ToFHat 类的实例。
- 参数:
i2c – I2C 对象。
address – 设备的 I2C 地址。默认值为 0x23。
io_timeout_ms – I2C 通信的超时时间。默认为 0 ms。
UIFLOW2:

ToFHat 类继承 ToFUnit 类,更多详情请参阅 unit.ToFUnit.Methods。

