DAC2 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 I2C 9from hardware import Pin 10from hat import DAC2Hat 11 12 13i2c0 = None 14hat_dac2_0 = None 15 16 17def setup(): 18 global i2c0, hat_dac2_0 19 20 M5.begin() 21 i2c0 = I2C(0, scl=Pin(26), sda=Pin(0), freq=100000) 22 hat_dac2_0 = DAC2Hat(i2c0, 0x59) 23 hat_dac2_0.set_dacoutput_voltage_range(hat_dac2_0.RANGE_10V) 24 hat_dac2_0.set_voltage(5, channel=hat_dac2_0.CHANNEL_0) 25 26 27def loop(): 28 global i2c0, hat_dac2_0 29 M5.update() 30 31 32if __name__ == "__main__": 33 try: 34 setup() 35 while True: 36 loop() 37 except (Exception, KeyboardInterrupt) as e: 38 try: 39 from utility import print_error_msg 40 41 print_error_msg(e) 42 except ImportError: 43 print("please update to latest firmware")
UiFlow2 应用示例:
stickc_plus2_dac2_example.m5f2
class DAC2Hat
Constructors
- class DAC2Hat(i2c, address: int | list | tuple = 0x59)
创建一个 DAC2 Hat 对象。
- 参数:
i2c – I2C 对象
address – DAC2 Hat 的 I2C 地址为 0x62。
UIFLOW2:

DAC2Hat 类继承自 DAC2Unit 类,更多详情请参阅 unit.DAC2Unit.Methods。

