diff --git a/_static/capacitive_touch_pads.jpg b/_static/capacitive_touch_pads.jpg new file mode 100644 index 0000000..14ab492 Binary files /dev/null and b/_static/capacitive_touch_pads.jpg differ diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index f813534..a306286 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -66,7 +66,8 @@ def light(self): """Light level in SI Lux.""" return self._photocell.value * 330 // (2 ** 16) -class Express: + +class Express: # pylint: disable=too-many-public-methods """Represents a single CircuitPlayground Express. Do not use more than one at a time.""" def __init__(self): @@ -110,6 +111,7 @@ def __init__(self): self._touch_A5 = None self._touch_A6 = None self._touch_A7 = None + self._touch_threshold_adjustment = 0 # Define acceleration: self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) @@ -188,6 +190,7 @@ def touch_A1(self): # pylint: disable=invalid-name """ if self._touch_A1 is None: self._touch_A1 = touchio.TouchIn(board.A1) + self._touch_A1.threshold += self._touch_threshold_adjustment return self._touch_A1.value @property @@ -207,6 +210,7 @@ def touch_A2(self): # pylint: disable=invalid-name """ if self._touch_A2 is None: self._touch_A2 = touchio.TouchIn(board.A2) + self._touch_A2.threshold += self._touch_threshold_adjustment return self._touch_A2.value @property @@ -226,6 +230,7 @@ def touch_A3(self): # pylint: disable=invalid-name """ if self._touch_A3 is None: self._touch_A3 = touchio.TouchIn(board.A3) + self._touch_A3.threshold += self._touch_threshold_adjustment return self._touch_A3.value @property @@ -245,6 +250,7 @@ def touch_A4(self): # pylint: disable=invalid-name """ if self._touch_A4 is None: self._touch_A4 = touchio.TouchIn(board.A4) + self._touch_A4.threshold += self._touch_threshold_adjustment return self._touch_A4.value @property @@ -264,6 +270,7 @@ def touch_A5(self): # pylint: disable=invalid-name """ if self._touch_A5 is None: self._touch_A5 = touchio.TouchIn(board.A5) + self._touch_A5.threshold += self._touch_threshold_adjustment return self._touch_A5.value @property @@ -283,6 +290,7 @@ def touch_A6(self): # pylint: disable=invalid-name """ if self._touch_A6 is None: self._touch_A6 = touchio.TouchIn(board.A6) + self._touch_A6.threshold += self._touch_threshold_adjustment return self._touch_A6.value @property @@ -302,8 +310,34 @@ def touch_A7(self): # pylint: disable=invalid-name """ if self._touch_A7 is None: self._touch_A7 = touchio.TouchIn(board.A7) + self._touch_A7.threshold += self._touch_threshold_adjustment return self._touch_A7.value + def adjust_touch_threshold(self, adjustment): + """Adjust the threshold needed to activate the capacitive touch pads. + Higher numbers make the touch pads less sensitive. + + :param int adjustment: The desired threshold increase + + .. image :: /_static/capacitive_touch_pads.jpg + :alt: Capacitive touch pads + + .. code-block:: python + + from adafruit_circuitplayground.express import cpx + + cpx.adjust_touch_threshold(200) + + while True: + if cpx.touch_A1: + print('Touched pad A1') + """ + for pad_name in ["_touch_A" + str(x) for x in range(1, 8)]: + touch_in = getattr(self, pad_name) + if touch_in: + touch_in.threshold += adjustment + self._touch_threshold_adjustment += adjustment + @property def pixels(self): """Sequence like object representing the ten NeoPixels around the outside