EARTH Unit
支持以下产品:
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 unit import EarthUnit 9 10 11label0 = None 12earth_0 = None 13 14 15def setup(): 16 global label0, earth_0 17 18 M5.begin() 19 Widgets.fillScreen(0x222222) 20 label0 = Widgets.Label("label0", 132, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 21 22 earth_0 = EarthUnit((36, 26)) 23 24 25def loop(): 26 global label0, earth_0 27 M5.update() 28 label0.setText(str(earth_0.get_digital_value())) 29 30 31if __name__ == "__main__": 32 try: 33 setup() 34 while True: 35 loop() 36 except (Exception, KeyboardInterrupt) as e: 37 try: 38 from utility import print_error_msg 39 40 print_error_msg(e) 41 except ImportError: 42 print("please update to latest firmware")
UiFlow2 应用示例
class Earth
Constructors
- class Earth(port)
创建一个 Earth 对象。
- 参数为:
port是端口的引脚编号。
UIFLOW2:

Methods
- EARTH.get_analog_value()
该方法允许你读取由 EARTH 采集的模拟量,并返回一个整数值。该值范围为 0 到 65535。
UIFLOW2:

- EARTH.get_digital_value()
该方法允许你读取 EARTH 收集到的数字数量,并返回一个整数值。该值范围为 0 到 1。
UIFLOW2:

- EARTH.get_voltage_mv()
该方法允许你读取 EARTH 采集到的电压值,并返回一个整数值。其范围为 0 到 3300。
UIFLOW2:

- EARTH.humidity()
该方法允许你读取由 EARTH 采集的电压值,并返回一个浮点值。范围为 0.0 到 1.0。
UIFLOW2:

- EARTH.set_calibrate()
此方法允许设置用于校准 EARTH 传感器的最大值(0-3300)和最小值(0-3300)。
UIFLOW2:


