diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index b4180d6..6ecfac1 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -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. @@ -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