ADCWiPy 类 – 模拟到数字转换

注意

This class is a non-standard ADC implementation for the WiPy. It is available simply as machine.ADC on the WiPy but is named in the documentation below as machine.ADCWiPy to distinguish it from the more general machine.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. ADCWiPy ( id = 0 , * , bits = 12 )

Create an ADC object associated with the given pin. This allows you to then read analog values on that pin. For more info check the 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.

方法

ADCWiPy. channel ( id , * , pin )

Create an analog pin. If only channel ID is given, the correct pin will be selected. Alternatively, only the pin can be passed and the correct channel will be selected. Examples:

# all of these are equivalent and enable ADC channel 1 on GP3
apin = adc.channel(1)
apin = adc.channel(pin='GP3')
apin = adc.channel(id=1, pin='GP3')
													
ADCWiPy. init ( )

启用 ADC (模拟到数字转换) 块。

ADCWiPy. deinit ( )

禁用 ADC (模拟到数字转换) 块。

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

ADC channels can be connected to internal points of the MCU or to GPIO pins. ADC channels are created using the ADC.channel method.

machine. adcchannel ( )

Fast method to read the channel value.

adcchannel. value ( )

Read the channel value.

adcchannel. init ( )

Re-init (and effectively enable) the ADC channel.

adcchannel. deinit ( )

Disable the ADC channel.