Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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