Skip to content

Commit 3b61cb0

Browse files
committed
Added ability to change touch threshold
1 parent 0535d1c commit 3b61cb0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

_static/capacitive_touch_pads.jpg

742 KB
Loading

adafruit_circuitplayground/express.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,33 @@ def shake(self):
171171
raise RuntimeError("Oops! You need a newer version of CircuitPython "
172172
"(2.2.0 or greater) to use cpx.shake.")
173173

174+
def adjust_touch_threshold(self, adjustment, pad_names):
175+
"""Adjust the threshold needed to activate the capacitive touch pads.
176+
Higher numbers make the touch pads less sensitive. Include the names
177+
of the touch pads for which you plan to change the threshold. They
178+
must be listed as in the example below.
179+
180+
:param int adjustment: The desired threshold increase
181+
:param str pad_names: The names, in a list, of the touch pads you intend to use
182+
183+
.. image :: /_static/capacitive_touch_pads.jpg
184+
:alt: Capacitive touch pads
185+
186+
.. code-block:: python
187+
188+
from adafruit_circuitplayground.express import cpx
189+
190+
cpx.adjust_touch_threshold(200, ["touch_A1", "touch_A2", "touch_A3", "touch_A4",
191+
"touch_A5", "touch_A6", "touch_A7"])
192+
193+
while True:
194+
if cpx.touch_A1:
195+
print('Touched pad A1')
196+
"""
197+
for pad_name in pad_names:
198+
getattr(cpx, pad_name)
199+
getattr(cpx, "_" + pad_name).threshold += adjustment
200+
174201
@property
175202
def touch_A1(self): # pylint: disable=invalid-name
176203
"""Detect touch on capacitive touch pad A1.

0 commit comments

Comments
 (0)