diff --git a/adafruit_ads1x15/ads1x15.py b/adafruit_ads1x15/ads1x15.py index 82c1d34..0f31f53 100644 --- a/adafruit_ads1x15/ads1x15.py +++ b/adafruit_ads1x15/ads1x15.py @@ -150,10 +150,10 @@ def _conversion_value(self, raw_adc): def _read(self, pin): """Perform an ADC read. Returns the signed integer result of the read.""" - fast = True - if self._last_pin_read != pin: + if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin: + return self._conversion_value(self.get_last_result(True)) + else: self._last_pin_read = pin - fast = False config = _ADS1X15_CONFIG_OS_SINGLE config |= (pin & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET config |= _ADS1X15_CONFIG_GAIN[self.gain] @@ -162,11 +162,11 @@ def _read(self, pin): config |= _ADS1X15_CONFIG_COMP_QUE_DISABLE self._write_register(_ADS1X15_POINTER_CONFIG, config) - if self.mode == Mode.SINGLE: - while not self._conversion_complete(): - pass + if self.mode == Mode.SINGLE: + while not self._conversion_complete(): + pass - return self._conversion_value(self.get_last_result(fast)) + return self._conversion_value(self.get_last_result(False)) def _conversion_complete(self): """Return status of ADC conversion.""" @@ -195,7 +195,6 @@ def _read_register(self, reg, fast=False): """Read 16 bit register value. If fast is True, the pointer register is not updated. """ - self.buf[0] = reg with self.i2c_device as i2c: if fast: i2c.readinto(self.buf, end=2) diff --git a/adafruit_ads1x15/analog_in.py b/adafruit_ads1x15/analog_in.py index 055d759..1d37097 100644 --- a/adafruit_ads1x15/analog_in.py +++ b/adafruit_ads1x15/analog_in.py @@ -76,6 +76,5 @@ def value(self): @property def voltage(self): """Returns the voltage from the ADC pin as a floating point value.""" - raw = self.value - volts = raw * (_ADS1X15_PGA_RANGE[self._ads.gain] / (2**(self._ads.bits-1) - 1)) + volts = self.value * _ADS1X15_PGA_RANGE[self._ads.gain] / 32767 return volts