Skip to content

Commit c84a39d

Browse files
committed
Improved Comments
Added comments for new functions
1 parent 017fb9f commit c84a39d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

adafruit_ads1x15/ads1x15.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ def _write_register(self, reg: int, value: int):
252252
i2c.write(self.buf)
253253

254254
def write_comparator_low_threshold(self, value: int):
255-
"""Write 16 bit value to register."""
255+
"""Write 16 bit value to Comparator Low Threshold register."""
256256
self.buf[0] = _ADS1X15_POINTER_LO_THRES
257257
self.buf[1] = (value >> 8) & 0xFF
258258
self.buf[2] = value & 0xFF
259259
with self.i2c_device as i2c:
260260
i2c.write(self.buf)
261261

262262
def write_comparator_high_threshold(self, value: int):
263-
"""Write 16 bit value to register."""
263+
"""Write 16 bit value to Comparator High Threshold register."""
264264
self.buf[0] = _ADS1X15_POINTER_HI_THRES
265265
self.buf[1] = (value >> 8) & 0xFF
266266
self.buf[2] = value & 0xFF

adafruit_ads1x15/analog_in.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ def voltage(self) -> float:
6666
return volts
6767

6868
def ADC_value(self, volts: float) -> int:
69+
"""Calculates integer for threshold registers from voltage level input"""
6970
value = int((volts * 32767) / _ADS1X15_PGA_RANGE[self._ads.gain])
7071
return value

examples/ads1x15_comparator_example.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
# Create Interrupt-driven input to track comparator changes
2626
int_pin = countio.Counter(board.GP9, edge=countio.Edge.RISE)
2727

28+
# Set comparator to assert after 1 ADC conversion
2829
ads.compqueue = 1
29-
ads.write_comparator_low_threshold(0x3E80)
30-
ads.write_comparator_high_threshold(0x3E90)
30+
# Set comparator low threshold to 2V
31+
ads.write_comparator_low_threshold(chan.ADC_value(2))
32+
# Set comparator high threshold to 2.002V. High threshold must be above low threshold
33+
ads.write_comparator_high_threshold(chan.ADC_value(2.002))
3134

3235
count = 0
3336
while True:

0 commit comments

Comments
 (0)