Skip to content

Commit 3b35d80

Browse files
kattnitannewt
authored andcommitted
Added double_tap to express class (#23)
Has a warning if the built in LIS3DH library is too old.
1 parent 27f1ab7 commit 3b35d80

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

adafruit_circuitplayground/express.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,36 @@ def __init__(self):
118118
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19)
119119
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
120120

121+
# Initialise tap:
122+
self._lis3dh.set_tap(2, 18, time_limit=4, time_latency=17, time_window=110)
123+
self._last_tap = False
124+
125+
@property
126+
def double_tap(self):
127+
"""True once after a double tap.
128+
129+
.. image :: /_static/accelerometer.jpg
130+
:alt: Accelerometer
131+
132+
Quickly tap the CPX twice to double-tap.
133+
134+
.. code-block:: python
135+
136+
from adafruit_circuitplayground.express import cpx
137+
138+
while True:
139+
if cpx.double_tap:
140+
print("Double tap!")
141+
"""
142+
try:
143+
tapped = self._lis3dh.tapped
144+
first_double_tap = tapped and not self._last_tap
145+
self._last_tap = tapped
146+
return first_double_tap
147+
except AttributeError:
148+
raise RuntimeError("Oops! You need a newer version of CircuitPython "
149+
"(2.2.0 or greater) to use this feature.")
150+
121151
@property
122152
def acceleration(self):
123153
"""Obtain data from the x, y and z axes.
@@ -172,7 +202,7 @@ def shake(self, shake_threshold=30):
172202
return self._lis3dh.shake(shake_threshold=shake_threshold)
173203
except AttributeError:
174204
raise RuntimeError("Oops! You need a newer version of CircuitPython "
175-
"(2.2.0 or greater) to use cpx.shake.")
205+
"(2.2.0 or greater) to use this feature.")
176206

177207
@property
178208
def touch_A1(self): # pylint: disable=invalid-name

0 commit comments

Comments
 (0)