@@ -47,7 +47,8 @@ def read_adc(self, channel, gain=1, data_rate=None):
47
47
"""Read a single ADC channel and return the ADC value as a signed integer
48
48
result. Channel must be a value within 0-3.
49
49
"""
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!' )
51
52
# Perform a single shot read and set the mux value to the channel plus
52
53
# the highest bit (bit 3) set.
53
54
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):
56
57
"""Read a single ADC channel and return the voltage value as a floating point
57
58
result. Channel must be a value within 0-3.
58
59
"""
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!' )
60
62
raw = self .read_adc (channel , gain , data_rate )
61
63
volts = raw * (ADS1X15_PGA_RANGE [gain ] / (2 ** (self .bits - 1 ) - 1 ))
62
64
return volts
@@ -67,7 +69,8 @@ def start_adc(self, channel, gain=1, data_rate=None):
67
69
function to read the most recent conversion result. Call stop_adc() to
68
70
stop conversions.
69
71
"""
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!' )
71
74
# Start continuous reads and set the mux value to the channel plus
72
75
# the highest bit (bit 3) set.
73
76
return self ._read (channel + 0x04 , gain , data_rate , ADS1X15_CONFIG_MODE_CONTINUOUS )
0 commit comments