2323 from typing import Dict , List , Optional
2424
2525 from busio import I2C
26- from microcontroller import Pin
2726except ImportError :
28- # define Pin to avoid the error:
29- # def read(self, pin: Pin, is_differential: bool = False) -> int:
30- # NameError: name 'Pin' is not defined
31- Pin = None
27+ pass
3228
3329_ADS1X15_DEFAULT_ADDRESS = const (0x48 )
3430_ADS1X15_POINTER_CONVERSION = const (0x00 )
5349 16 : 0x0A00 ,
5450}
5551
56- # Pins
57- A0 = 0
58- """Analog Pin 0"""
59- A1 = 1
60- """Analog Pin 1"""
61- A2 = 2
62- """Analog Pin 2"""
63- A3 = 3
64- """Analog Pin 3"""
52+
53+ class Pin :
54+ """An enum-like class representing possible ADC pins."""
55+
56+ A0 = 0
57+ """Analog Pin 0"""
58+ A1 = 1
59+ """Analog Pin 1"""
60+ A2 = 2
61+ """Analog Pin 2"""
62+ A3 = 3
63+ """Analog Pin 3"""
6564
6665
6766class Mode :
@@ -137,7 +136,7 @@ class ADS1x15:
137136
138137 def __init__ (
139138 self ,
140- i2c : I2C ,
139+ i2c : " I2C" ,
141140 gain : float = 1 ,
142141 data_rate : Optional [int ] = None ,
143142 mode : int = Mode .SINGLE ,
@@ -330,7 +329,7 @@ def comparator_latch(self, comp_latch: int) -> None:
330329 if self .initialized :
331330 self ._write_config ()
332331
333- def read (self , pin : Pin ) -> int :
332+ def read (self , pin : Optional [ int ] ) -> int :
334333 """I2C Interface for ADS1x15-based ADCs reads.
335334
336335 :param ~microcontroller.Pin pin: individual or differential pin.
@@ -350,7 +349,7 @@ def _conversion_value(self, raw_adc: int) -> int:
350349 """
351350 raise NotImplementedError ("Subclass must implement _conversion_value function!" )
352351
353- def _read (self , pin : Pin ) -> int :
352+ def _read (self , pin : Optional [ int ] ) -> int :
354353 """Perform an ADC read. Returns the signed integer result of the read."""
355354 # Immediately return conversion register result if in CONTINUOUS mode
356355 # and pin has not changed
0 commit comments