from machine import Pin, ADC  #引入ADC模块
import time

pot = ADC(Pin(1),atten=ADC.ATTN_11DB)  #定义1脚为ADC脚,衰减设置范围:输入电压0-3.3v
pot.width(ADC.WIDTH_12BIT) #配置采样精度为12bit
#pot.atten(ADC.ATTN_11DB)   #衰减设置范围:输入电压0-3.3v

while True:
  pot_value1 = pot.read() #读取ADC采样值,范围[0,4095]
  pot_value2 = pot.read_u16()#读取ADC采样值,范围[0,65535]
  pot_value3 = pot.read_uv()#读取ADC采样转换后的电压值,单位为微伏
  print("采用值1={:5d},转换值={:.2f}V".format(pot_value1, pot_value1 / 4095 * 3.3))
  print("采用值2={:5d},转换值={:.2f}V".format(pot_value2, pot_value2 / 65535 * 3.3))
  print("采用值3={:.2f}V\r\n".format(pot_value3/1000000))
  time.sleep(1)