Skip to content

Added double_tap to express class #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2017
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