Skip to content

Commit 1754752

Browse files
authored
Part 2
1 parent cdd12b8 commit 1754752

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

adafruit_ads1x15/single_ended.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def read_adc(self, channel, gain=1, data_rate=None):
4747
"""Read a single ADC channel and return the ADC value as a signed integer
4848
result. Channel must be a value within 0-3.
4949
"""
50-
assert 0 <= channel <= 3, 'Channel must be a value within 0-3!'
50+
if not 0 <= channel <= 3:
51+
raise ValueError('Channel must be a value within 0-3!')
5152
# Perform a single shot read and set the mux value to the channel plus
5253
# the highest bit (bit 3) set.
5354
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):
5657
"""Read a single ADC channel and return the voltage value as a floating point
5758
result. Channel must be a value within 0-3.
5859
"""
59-
assert 0 <= channel <= 3, 'Channel must be a value within 0-3!'
60+
if not 0 <= channel <= 3:
61+
raise ValueError('Channel must be a value within 0-3!')
6062
raw = self.read_adc(channel, gain, data_rate)
6163
volts = raw * (ADS1X15_PGA_RANGE[gain] / (2**(self.bits-1) - 1))
6264
return volts
@@ -67,7 +69,8 @@ def start_adc(self, channel, gain=1, data_rate=None):
6769
function to read the most recent conversion result. Call stop_adc() to
6870
stop conversions.
6971
"""
70-
assert 0 <= channel <= 3, 'Channel must be a value within 0-3!'
72+
if not 0 <= channel <= 3:
73+
raise ValueError('Channel must be a value within 0-3!')
7174
# Start continuous reads and set the mux value to the channel plus
7275
# the highest bit (bit 3) set.
7376
return self._read(channel + 0x04, gain, data_rate, ADS1X15_CONFIG_MODE_CONTINUOUS)

0 commit comments

Comments
 (0)