Skip to content

Commit 3a0c653

Browse files
committed
allow easy configuration of single or double tapping
1 parent b255c2c commit 3a0c653

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

adafruit_circuitplayground/express.py

+29-6
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,51 @@ def __init__(self):
119119
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
120120

121121
# Initialise tap:
122+
self.detect_taps = 2
123+
124+
@property
125+
def detect_taps(self):
126+
"""Configure how many taps are used to set off the 'tapped' property!
127+
128+
.. image :: /_static/accelerometer.jpg
129+
:alt: Accelerometer
130+
131+
.. code-block:: python
132+
133+
from adafruit_circuitplayground.express import cpx
134+
135+
cpx.detect_taps = 1
136+
while True:
137+
if cpx.tapped:
138+
print("Single Tap detected!")
139+
"""
140+
return self._detect_taps
141+
142+
@detect_taps.setter
143+
def detect_taps(self, value):
144+
self._detect_taps = value
122145
try:
123-
self._lis3dh.set_tap(2, 18, time_limit=4, time_latency=17, time_window=110)
146+
self._lis3dh.set_tap(value, 18, time_limit=4, time_latency=17, time_window=110)
124147
except AttributeError:
125148
pass
126149
self._last_tap = False
127150

128151
@property
129-
def double_tap(self):
130-
"""True once after a double tap.
152+
def tapped(self):
153+
"""True once after a tap detection. use cpx.detect_taps to assign single (1) or double (2) tap
131154
132155
.. image :: /_static/accelerometer.jpg
133156
:alt: Accelerometer
134157
135-
Quickly tap the CPX twice to double-tap.
158+
Quickly tap the CPX twice to double-tap, or tap once for single-tap
136159
137160
.. code-block:: python
138161
139162
from adafruit_circuitplayground.express import cpx
140163
141164
while True:
142-
if cpx.double_tap:
143-
print("Double tap!")
165+
if cpx.tapped:
166+
print("Tapped!")
144167
"""
145168
try:
146169
tapped = self._lis3dh.tapped

0 commit comments

Comments
 (0)