Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,36 @@ def __init__(self):
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19)
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G

# Initialise tap:
self._lis3dh.set_tap(2, 18, time_limit=4, time_latency=17, time_window=110)
self._last_tap = False

@property
def double_tap(self):
"""True once after a double tap.

.. image :: /_static/accelerometer.jpg
:alt: Accelerometer

Quickly tap the CPX twice to double-tap.

.. code-block:: python

from adafruit_circuitplayground.express import cpx

while True:
if cpx.double_tap:
print("Double tap!")
"""
try:
tapped = self._lis3dh.tapped
first_double_tap = tapped and not self._last_tap
self._last_tap = tapped
return first_double_tap
except AttributeError:
raise RuntimeError("Oops! You need a newer version of CircuitPython "
"(2.2.0 or greater) to use this feature.")

@property
def acceleration(self):
"""Obtain data from the x, y and z axes.
Expand Down Expand Up @@ -172,7 +202,7 @@ def shake(self, shake_threshold=30):
return self._lis3dh.shake(shake_threshold=shake_threshold)
except AttributeError:
raise RuntimeError("Oops! You need a newer version of CircuitPython "
"(2.2.0 or greater) to use cpx.shake.")
"(2.2.0 or greater) to use this feature.")

@property
def touch_A1(self): # pylint: disable=invalid-name
Expand Down