Skip to content

Commit 6fc77d3

Browse files
authored
Merge pull request #26 from ladyada/master
allow easy configuration of single or double tapping
2 parents b255c2c + ff019a3 commit 6fc77d3

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

adafruit_circuitplayground/express.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,54 @@ def __init__(self):
119119
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
120120

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

128153
@property
129-
def double_tap(self):
130-
"""True once after a double tap.
154+
def tapped(self):
155+
"""True once after a tap detection. use cpx.detect_taps to assign single (1) or
156+
double (2) tap
131157
132158
.. image :: /_static/accelerometer.jpg
133159
:alt: Accelerometer
134160
135-
Quickly tap the CPX twice to double-tap.
161+
Quickly tap the CPX twice to double-tap, or tap once for single-tap
136162
137163
.. code-block:: python
138164
139165
from adafruit_circuitplayground.express import cpx
140166
141167
while True:
142-
if cpx.double_tap:
143-
print("Double tap!")
168+
if cpx.tapped:
169+
print("Tapped!")
144170
"""
145171
try:
146172
tapped = self._lis3dh.tapped

0 commit comments

Comments
 (0)