diff --git a/adafruit_ads1x15/differential.py b/adafruit_ads1x15/differential.py index 9a4a148..fb0ae56 100644 --- a/adafruit_ads1x15/differential.py +++ b/adafruit_ads1x15/differential.py @@ -51,7 +51,8 @@ def read_adc_difference(self, differential, gain=1, data_rate=None): - 2 = Channel 1 minus channel 3 - 3 = Channel 2 minus channel 3 """ - assert 0 <= differential <= 3, 'Differential must be a value within 0-3!' + if not 0 <= differential <= 3: + raise ValueError('Differential must be a value within 0-3!') # Perform a single shot read using the provided differential value # as the mux value (which will enable differential mode). return self._read(differential, gain, data_rate, ADS1X15_CONFIG_MODE_SINGLE) @@ -64,7 +65,8 @@ def read_volts_difference(self, differential, gain=1, data_rate=None): - 2 = Channel 1 minus channel 3 - 3 = Channel 2 minus channel 3 """ - assert 0 <= differential <= 3, 'Differential must be a value within 0-3!' + if not 0 <= differential <= 3: + raise ValueError('Differential must be a value within 0-3!') raw = self.read_adc_difference(differential, gain, data_rate) volts = raw * (ADS1X15_PGA_RANGE[gain] / (2**(self.bits-1) - 1)) return volts @@ -80,7 +82,8 @@ def start_adc_difference(self, differential, gain=1, data_rate=None): function continuously to read the most recent conversion result. Call stop_adc() to stop conversions. """ - assert 0 <= differential <= 3, 'Differential must be a value within 0-3!' + if not 0 <= differential <= 3: + raise ValueError('Differential must be a value within 0-3!') # Perform a single shot read using the provided differential value # as the mux value (which will enable differential mode). return self._read(differential, gain, data_rate, ADS1X15_CONFIG_MODE_CONTINUOUS) diff --git a/adafruit_ads1x15/single_ended.py b/adafruit_ads1x15/single_ended.py index eca1313..1318a46 100644 --- a/adafruit_ads1x15/single_ended.py +++ b/adafruit_ads1x15/single_ended.py @@ -47,7 +47,8 @@ def read_adc(self, channel, gain=1, data_rate=None): """Read a single ADC channel and return the ADC value as a signed integer result. Channel must be a value within 0-3. """ - assert 0 <= channel <= 3, 'Channel must be a value within 0-3!' + if not 0 <= channel <= 3: + raise ValueError('Channel must be a value within 0-3!') # Perform a single shot read and set the mux value to the channel plus # the highest bit (bit 3) set. return self._read(channel + 0x04, gain, data_rate, ADS1X15_CONFIG_MODE_SINGLE) @@ -56,7 +57,8 @@ def read_volts(self, channel, gain=1, data_rate=None): """Read a single ADC channel and return the voltage value as a floating point result. Channel must be a value within 0-3. """ - assert 0 <= channel <= 3, 'Channel must be a value within 0-3!' + if not 0 <= channel <= 3: + raise ValueError('Channel must be a value within 0-3!') raw = self.read_adc(channel, gain, data_rate) volts = raw * (ADS1X15_PGA_RANGE[gain] / (2**(self.bits-1) - 1)) return volts @@ -67,7 +69,8 @@ def start_adc(self, channel, gain=1, data_rate=None): function to read the most recent conversion result. Call stop_adc() to stop conversions. """ - assert 0 <= channel <= 3, 'Channel must be a value within 0-3!' + if not 0 <= channel <= 3: + raise ValueError('Channel must be a value within 0-3!') # Start continuous reads and set the mux value to the channel plus # the highest bit (bit 3) set. return self._read(channel + 0x04, gain, data_rate, ADS1X15_CONFIG_MODE_CONTINUOUS)