ADC类 – 模数转换

用法:

import machine

adc = machine.ADC()             # create an ADC object
apin = adc.channel(pin='GP3')   # create an analog pin on GP3
val = apin()                    # read an analog value

构造函数

class machine.ADC(id=0, \*, bits=12)

创建与给定引脚相关联的ADC对象。 这样你就可以读取引脚上的模拟值。 有关更多信息,请查看 pinout and alternate functions table.

警告

ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it can withstand). When GP2, GP3, GP4 or GP5 are remapped to the ADC block, 1.8 V is the maximum. If these pins are used in digital mode, then the maximum allowed input is 3.6V. ADC引脚输入范围为 0-1.4V (1.8V为它所能承受的绝对最大值)。 当GP2、GP3、GP4或GP5被重映射到ADC块时,1.8V为最大值。 如果这些引脚在数字模式下使用,那么最大允许输入是3.6V。

方法

ADC.channel(id, \*, pin)

创建一个模拟引脚。只要给出通道ID,就会选择正确的引脚。 或者只要传递引脚参数,就会选择正确的通道。例子:

# 所有这些都是等效的,并在GP3上启用ADC通道1
apin = adc.channel(1)
apin = adc.channel(pin='GP3')
apin = adc.channel(id=1, pin='GP3')
ADC.init()

启用ADC块。

ADC.deinit()

禁用ADC块。

ADCChannel 类 — 从内部或外部源读取模拟值

ADC通道可以连接到MCU的内部点或GPIO引脚。 ADC通道是使用ADC.channel方法创建的。

machine.adcchannel()

快速读取通道值的方法。

adcchannel.value()

读取通道值。

adcchannel.init()

重新初始化(并有效启用)ADC通道。

adcchannel.deinit()

禁用ADC通道。