Skip to content

Commit

Permalink
Merge pull request #90 from todbot/main
Browse files Browse the repository at this point in the history
Propagate delay param from read() to analog_read()
  • Loading branch information
caternuson committed Dec 10, 2021
2 parents d561fd7 + 9fa9b61 commit f06ac21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 3 additions & 2 deletions adafruit_seesaw/analoginput.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ class AnalogInput:
:param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device
:param int pin: The pin number on the device"""

def __init__(self, seesaw, pin):
def __init__(self, seesaw, pin, delay=0.008):
self._seesaw = seesaw
self._pin = pin
self._delay = delay

def deinit(self):
pass

@property
def value(self):
"""The current analog value on the pin, as an integer from 0..65535 (inclusive)"""
return self._seesaw.analog_read(self._pin)
return self._seesaw.analog_read(self._pin, self._delay)

@property
def reference_voltage(self):
Expand Down
9 changes: 2 additions & 7 deletions adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def get_GPIO_interrupt_flag(self, delay=0.008):
self.read(_GPIO_BASE, _GPIO_INTFLAG, buf, delay=delay)
return struct.unpack(">I", buf)[0]

def analog_read(self, pin):
def analog_read(self, pin, delay=0.008):
"""Read the value of an analog pin by number"""
buf = bytearray(2)
if pin not in self.pin_mapping.analog_pins:
Expand All @@ -253,13 +253,8 @@ def analog_read(self, pin):
elif self.chip_id == _SAMD09_HW_ID_CODE:
offset = self.pin_mapping.analog_pins.index(pin)

self.read(
_ADC_BASE,
_ADC_CHANNEL_OFFSET + offset,
buf,
)
self.read(_ADC_BASE, _ADC_CHANNEL_OFFSET + offset, buf, delay)
ret = struct.unpack(">H", buf)[0]
time.sleep(0.001)
return ret

def touch_read(self, pin):
Expand Down

0 comments on commit f06ac21

Please sign in to comment.