@@ -67,7 +67,7 @@ def light(self):
67
67
return self ._photocell .value * 330 // (2 ** 16 )
68
68
69
69
70
- class Express : #pylint: disable-msg=R0904
70
+ class Express : # pylint: disable-msg=R0904
71
71
"""Represents a single CircuitPlayground Express. Do not use more than one at
72
72
a time."""
73
73
def __init__ (self ):
@@ -111,6 +111,7 @@ def __init__(self):
111
111
self ._touch_A5 = None
112
112
self ._touch_A6 = None
113
113
self ._touch_A7 = None
114
+ self ._touch_threshold_adjustment = 0
114
115
115
116
# Define acceleration:
116
117
self ._i2c = busio .I2C (board .ACCELEROMETER_SCL , board .ACCELEROMETER_SDA )
@@ -172,34 +173,6 @@ def shake(self):
172
173
raise RuntimeError ("Oops! You need a newer version of CircuitPython "
173
174
"(2.2.0 or greater) to use cpx.shake." )
174
175
175
- @classmethod
176
- def adjust_touch_threshold (cls , adjustment , pad_names ):
177
- """Adjust the threshold needed to activate the capacitive touch pads.
178
- Higher numbers make the touch pads less sensitive. Include the names
179
- of the touch pads for which you plan to change the threshold. They
180
- must be listed as in the example below.
181
-
182
- :param int adjustment: The desired threshold increase
183
- :param str pad_names: The names, in a list, of the touch pads you intend to use
184
-
185
- .. image :: /_static/capacitive_touch_pads.jpg
186
- :alt: Capacitive touch pads
187
-
188
- .. code-block:: python
189
-
190
- from adafruit_circuitplayground.express import cpx
191
-
192
- cpx.adjust_touch_threshold(200, ["touch_A1", "touch_A2", "touch_A3", "touch_A4",
193
- "touch_A5", "touch_A6", "touch_A7"])
194
-
195
- while True:
196
- if cpx.touch_A1:
197
- print('Touched pad A1')
198
- """
199
- for pad_name in pad_names :
200
- getattr (cpx , pad_name )
201
- getattr (cpx , "_" + pad_name ).threshold += adjustment
202
-
203
176
@property
204
177
def touch_A1 (self ): # pylint: disable=invalid-name
205
178
"""Detect touch on capacitive touch pad A1.
@@ -217,6 +190,7 @@ def touch_A1(self): # pylint: disable=invalid-name
217
190
"""
218
191
if self ._touch_A1 is None :
219
192
self ._touch_A1 = touchio .TouchIn (board .A1 )
193
+ self ._touch_A1 .threshold += self ._touch_threshold_adjustment
220
194
return self ._touch_A1 .value
221
195
222
196
@property
@@ -236,6 +210,7 @@ def touch_A2(self): # pylint: disable=invalid-name
236
210
"""
237
211
if self ._touch_A2 is None :
238
212
self ._touch_A2 = touchio .TouchIn (board .A2 )
213
+ self ._touch_A2 .threshold += self ._touch_threshold_adjustment
239
214
return self ._touch_A2 .value
240
215
241
216
@property
@@ -255,6 +230,7 @@ def touch_A3(self): # pylint: disable=invalid-name
255
230
"""
256
231
if self ._touch_A3 is None :
257
232
self ._touch_A3 = touchio .TouchIn (board .A3 )
233
+ self ._touch_A3 .threshold += self ._touch_threshold_adjustment
258
234
return self ._touch_A3 .value
259
235
260
236
@property
@@ -274,6 +250,7 @@ def touch_A4(self): # pylint: disable=invalid-name
274
250
"""
275
251
if self ._touch_A4 is None :
276
252
self ._touch_A4 = touchio .TouchIn (board .A4 )
253
+ self ._touch_A4 .threshold += self ._touch_threshold_adjustment
277
254
return self ._touch_A4 .value
278
255
279
256
@property
@@ -293,6 +270,7 @@ def touch_A5(self): # pylint: disable=invalid-name
293
270
"""
294
271
if self ._touch_A5 is None :
295
272
self ._touch_A5 = touchio .TouchIn (board .A5 )
273
+ self ._touch_A5 .threshold += self ._touch_threshold_adjustment
296
274
return self ._touch_A5 .value
297
275
298
276
@property
@@ -312,6 +290,7 @@ def touch_A6(self): # pylint: disable=invalid-name
312
290
"""
313
291
if self ._touch_A6 is None :
314
292
self ._touch_A6 = touchio .TouchIn (board .A6 )
293
+ self ._touch_A6 .threshold += self ._touch_threshold_adjustment
315
294
return self ._touch_A6 .value
316
295
317
296
@property
@@ -331,8 +310,34 @@ def touch_A7(self): # pylint: disable=invalid-name
331
310
"""
332
311
if self ._touch_A7 is None :
333
312
self ._touch_A7 = touchio .TouchIn (board .A7 )
313
+ self ._touch_A7 .threshold += self ._touch_threshold_adjustment
334
314
return self ._touch_A7 .value
335
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
+
336
341
@property
337
342
def pixels (self ):
338
343
"""Sequence like object representing the ten NeoPixels around the outside
0 commit comments