.. currentmodule:: machine .. _machine.ADCWiPy: class ADCWiPy -- analog to digital conversion 类ADCWiPy -- 拟到数字的转换 ============================================= .. note:: .. 注意:: 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 :ref:`machine.ADC ` class. 这个类是WiPy的非标准ADC实现。 它可以简单地称为' ' machine。“ADC”在WiPy上却被命名为 下面的文档为' ' machine。把它和…区分开来 更普遍的:裁判:“机器。ADC <机器。ADC >”类。 Usage:: 用法:: import machine 进口机器 adc = machine.ADC() # create an ADC object adc = machine.ADC() # 创建一个ADC对象 apin = adc.channel(pin='GP3') # create an analog pin on GP3 apin = adc.channel(pin='GP3') # 在GP3上创建一个模拟引脚 val = apin() # read an analog value val = apin() # 读取模拟值 Constructors 构造函数 ------------ .. class:: ADCWiPy(id=0, \*, bits=12) .. 类:: 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. `_ 创建一个与给定的pin相关联的ADC对象。 这允许你读模拟值的引脚。 更多信息请查看' pinout和备用函数 表格。`_ .. warning:: .. 警告:: 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.8 V。如果这些引脚在数字模式下使用, 那么最大允许输入是3.6V。 Methods 方法 ------- .. method:: 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:: 创建模拟引脚。如果只有通道ID是给定的,正确的pin将 被选中。或者,只有大头针可以通过和正确的 频道将被选择。例子:: # all of these are equivalent and enable ADC channel 1 on GP3 # 所有这些都是等效的,并在GP3上启用ADC通道1 apin = adc.channel(1) apin = adc.channel(pin='GP3') apin = adc.channel(id=1, pin='GP3') .. method:: ADCWiPy.init() Enable the ADC block. 启用ADC块。 .. method:: ADCWiPy.deinit() Disable the ADC block. 禁用ADC块。 class ADCChannel --- read analog values from internal or external sources 类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. ADC通道可以连接到MCU的内部点或GPIO引脚上。 ADC通道是使用ADC创建的。通道的方法。 .. method:: adcchannel() Fast method to read the channel value. 快速读取通道值的方法。 .. method:: adcchannel.value() Read the channel value. 读取通道值。 .. method:: adcchannel.init() Re-init (and effectively enable) the ADC channel. 重新init(并有效地启用)ADC通道。 .. method:: adcchannel.deinit() Disable the ADC channel. 禁用ADC通道。