Python machine 模块,ADC 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用machine.ADC

项目:micropython-share    作者:pacmac    | 项目源码 | 文件源码
def _config(self, duty_cycle=0):
        if self._function == 'dig':
            _mode = machine.Pin.OUT if self._mode == 'out' else machine.Pin.IN
            if self._pull == 'pu':
                _pull = machine.Pin.PULL_UP
            elif self._pull == 'pd':
                _pull = machine.Pin.PULL_DOWN
            else:
                _pull = None
            self._pin = machine.Pin(self._name, mode=_mode, pull=_pull, drive=machine.Pin.MED_POWER)
        elif self._function == 'ana':
            adc = machine.ADC(bits=12)
            self._apin = adc.channel(pin=self._name)
        else:
            self._pwm = machine.PWM(machine.Pin(self.pin_num),duty=duty_cycle * 100,freq=1000)
            #timer = machine.Timer(HwPin._TimerMap[self._name][0], mode=machine.Timer.PWM)
            #self._pwm = timer.channel(HwPin._TimerMap[self._name][1], freq=20000, duty_cycle=(duty_cycle * 100))
项目:kiota    作者:Morteo    | 项目源码 | 文件源码
def read(self):

    self.pin.value(True)
    payload = { 'moisture': str(machine.ADC(self.config["gpio_ADC"]).read()) }
    self.pin.value(False)

    return payload
项目:illuminOS    作者:idimitrakopoulos    | 项目源码 | 文件源码
def __init__(self, pin, vhigh, vlow):
        self.sensor = machine.ADC(pin)
        self.vhigh = vhigh
        self.vlow = vlow
项目:ulnoiot    作者:ulno    | 项目源码 | 文件源码
def __init__(self, name, precision=1, threshold=None,
                 on_change=None, report_change=True):
        self.precision=precision
        self.threshold = None
        if threshold is not None:
            self.threshold=max(1,min(threshold,1023))
        self.current_value=-10000
        Device.__init__(self, name, ADC(0), on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value
项目:thingflow-python    作者:mpi-sws-rse    | 项目源码 | 文件源码
def __init__(self, sensor_id='adc', min_rd=0, max_rd=1024,
                 min_val=0, max_val=1):
        '''Initialize sensor

           min_rd and max_rd are used in sample for sensor calibration
           min_val and max_val are the sample limits
        '''
        self.sensor_id = sensor_id
        self.min_rd = min_rd
        self.max_rd = max_rd
        self.min_val = min_val
        self.max_val = max_val
        self.coef = (max_val - min_val) / (max_rd - min_rd)
        self.adc = ADC(0)
项目:thingflow-python    作者:mpi-sws-rse    | 项目源码 | 文件源码
def read(self) -> int:
        '''Get a sensor reading using Micropython API

           Return 0-1024 direct ADC (0~3.3v) reading
        '''
        return self.adc.read()
项目:thingflow-python    作者:mpi-sws-rse    | 项目源码 | 文件源码
def sample(self) -> float:
        '''Get an ADC interpolated reading using ThingFlow sensor API

           Return min_val~max_val
        '''
        reading = self.read()
        return self.min_val + (reading - self.min_rd) * self.coef
项目:templogger    作者:aequitas    | 项目源码 | 文件源码
def read_voltage():
    """Read VDD voltage and LiPO battery level."""
    voltage = ADC(ADC_NUM).read() / 1000
    return {
        'voltage': voltage,
        'battery': 'low' if voltage < 3.5 else 'ok',
    }
项目:py-mpu6050    作者:larsks    | 项目源码 | 文件源码
def set_adc_mode(mode):
    sector_size = bdev.SEC_SIZE
    flash_size = esp.flash_size() # device dependent
    init_sector = int(flash_size / sector_size - 4)
    data = bytearray(esp.flash_read(init_sector * sector_size, sector_size))
    if data[107] == mode:
        return  # flash is already correct; nothing to do
    else:
        data[107] = mode  # re-write flash
        esp.flash_erase(init_sector)
        esp.flash_write(init_sector * sector_size, data)
        print("ADC mode changed in flash; restart to use it!")
        return
项目:py-mpu6050    作者:larsks    | 项目源码 | 文件源码
def battery():
    vcc = machine.ADC(1)
    return vcc.read()
项目:esp8266    作者:fadushin    | 项目源码 | 文件源码
def vcc():
    import machine
    mv = machine.ADC(0)
    return mv.read() * 1.024
项目:INF3910-LoPy    作者:TobiasBorgen    | 项目源码 | 文件源码
def __init__(self):
    self.timeout = time()

    try:
      self.pin_speed = Pin(self.PIN_SPEED, mode = Pin.IN, pull = Pin.PULL_UP)
      self.pin_speed.callback(Pin.IRQ_RISING, self.rotations_handler)

      self.adc = ADC()
      self.pin_dir = self.adc.channel(pin = self.PIN_DIR)
    except Exception as e:
      # Should throw exception to stop execution
      pass