ADC Hat

支持以下产品:

ADC

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 ADCHat
10
11
12label0 = None
13i2c0 = None
14hat_adc_0 = None
15
16
17def setup():
18    global label0, i2c0, hat_adc_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_adc_0 = ADCHat(i2c0)
25
26
27def loop():
28    global label0, i2c0, hat_adc_0
29    M5.update()
30    label0.setText(str(hat_adc_0.get_voltage()))
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 应用示例:

example.png

stickc_plus2_adc_example.m5f2

class CANUnit

Constructors

class ADCHat(i2c, address: int = 0x48)

创建 ADC Hat 的实例。

参数:
  • i2c – I2C 总线

  • address – ADC Hat 的 I2C 地址

UIFLOW2:

init.png

ADCHat 类继承自 ADCUnit 类,更多详情请参阅 unit.ADCUnit.Methods