@@ -66,7 +66,8 @@ def light(self):
66
66
"""Light level in SI Lux."""
67
67
return self ._photocell .value * 330 // (2 ** 16 )
68
68
69
- class Express :
69
+
70
+ class Express : # pylint: disable=too-many-public-methods
70
71
"""Represents a single CircuitPlayground Express. Do not use more than one at
71
72
a time."""
72
73
def __init__ (self ):
@@ -110,6 +111,7 @@ def __init__(self):
110
111
self ._touch_A5 = None
111
112
self ._touch_A6 = None
112
113
self ._touch_A7 = None
114
+ self ._touch_threshold_adjustment = 0
113
115
114
116
# Define acceleration:
115
117
self ._i2c = busio .I2C (board .ACCELEROMETER_SCL , board .ACCELEROMETER_SDA )
@@ -188,6 +190,7 @@ def touch_A1(self): # pylint: disable=invalid-name
188
190
"""
189
191
if self ._touch_A1 is None :
190
192
self ._touch_A1 = touchio .TouchIn (board .A1 )
193
+ self ._touch_A1 .threshold += self ._touch_threshold_adjustment
191
194
return self ._touch_A1 .value
192
195
193
196
@property
@@ -207,6 +210,7 @@ def touch_A2(self): # pylint: disable=invalid-name
207
210
"""
208
211
if self ._touch_A2 is None :
209
212
self ._touch_A2 = touchio .TouchIn (board .A2 )
213
+ self ._touch_A2 .threshold += self ._touch_threshold_adjustment
210
214
return self ._touch_A2 .value
211
215
212
216
@property
@@ -226,6 +230,7 @@ def touch_A3(self): # pylint: disable=invalid-name
226
230
"""
227
231
if self ._touch_A3 is None :
228
232
self ._touch_A3 = touchio .TouchIn (board .A3 )
233
+ self ._touch_A3 .threshold += self ._touch_threshold_adjustment
229
234
return self ._touch_A3 .value
230
235
231
236
@property
@@ -245,6 +250,7 @@ def touch_A4(self): # pylint: disable=invalid-name
245
250
"""
246
251
if self ._touch_A4 is None :
247
252
self ._touch_A4 = touchio .TouchIn (board .A4 )
253
+ self ._touch_A4 .threshold += self ._touch_threshold_adjustment
248
254
return self ._touch_A4 .value
249
255
250
256
@property
@@ -264,6 +270,7 @@ def touch_A5(self): # pylint: disable=invalid-name
264
270
"""
265
271
if self ._touch_A5 is None :
266
272
self ._touch_A5 = touchio .TouchIn (board .A5 )
273
+ self ._touch_A5 .threshold += self ._touch_threshold_adjustment
267
274
return self ._touch_A5 .value
268
275
269
276
@property
@@ -283,6 +290,7 @@ def touch_A6(self): # pylint: disable=invalid-name
283
290
"""
284
291
if self ._touch_A6 is None :
285
292
self ._touch_A6 = touchio .TouchIn (board .A6 )
293
+ self ._touch_A6 .threshold += self ._touch_threshold_adjustment
286
294
return self ._touch_A6 .value
287
295
288
296
@property
@@ -302,8 +310,34 @@ def touch_A7(self): # pylint: disable=invalid-name
302
310
"""
303
311
if self ._touch_A7 is None :
304
312
self ._touch_A7 = touchio .TouchIn (board .A7 )
313
+ self ._touch_A7 .threshold += self ._touch_threshold_adjustment
305
314
return self ._touch_A7 .value
306
315
316
+ def adjust_touch_threshold (self , adjustment ):
317
+ """Adjust the threshold needed to activate the capacitive touch pads.
318
+ Higher numbers make the touch pads less sensitive.
319
+
320
+ :param int adjustment: The desired threshold increase
321
+
322
+ .. image :: /_static/capacitive_touch_pads.jpg
323
+ :alt: Capacitive touch pads
324
+
325
+ .. code-block:: python
326
+
327
+ from adafruit_circuitplayground.express import cpx
328
+
329
+ cpx.adjust_touch_threshold(200)
330
+
331
+ while True:
332
+ if cpx.touch_A1:
333
+ print('Touched pad A1')
334
+ """
335
+ for pad_name in ["_touch_A" + str (x ) for x in range (1 , 8 )]:
336
+ touch_in = getattr (self , pad_name )
337
+ if touch_in :
338
+ touch_in .threshold += adjustment
339
+ self ._touch_threshold_adjustment += adjustment
340
+
307
341
@property
308
342
def pixels (self ):
309
343
"""Sequence like object representing the ten NeoPixels around the outside
0 commit comments