Skip to content

allow easy configuration of single or double tapping #26

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 3 commits into from
Dec 27, 2017
Merged
Changes from 2 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
37 changes: 31 additions & 6 deletions adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,53 @@ def __init__(self):
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G

# Initialise tap:
self._last_tap = False
self._detect_taps = 1
self.detect_taps = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is detect_taps included twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one is the setter (detect_taps) and one is the variable that is set by the setter (_detect_taps)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you!


@property
def detect_taps(self):
"""Configure how many taps are used to set off the 'tapped' property!

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

.. code-block:: python

from adafruit_circuitplayground.express import cpx

cpx.detect_taps = 1
while True:
if cpx.tapped:
print("Single Tap detected!")
"""
return self._detect_taps

@detect_taps.setter
def detect_taps(self, value):
self._detect_taps = value
try:
self._lis3dh.set_tap(2, 18, time_limit=4, time_latency=17, time_window=110)
self._lis3dh.set_tap(value, 18, time_limit=4, time_latency=17, time_window=110)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These numbers work for double-tapping, but it seems like they are not great for single-tap. Did you have issues with sensitivity? I can't touch the board without setting single-tap off.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can tweak it for single/double, maybe set threshhold to 24 or so for single!

Copy link
Contributor

@kattni kattni Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to set single-tap threshold to 70 with them separated before single-tap wasn't going off constantly. I'll test some numbers and get back to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure sounds good, yeah with 8G its hard to get good numbers!

except AttributeError:
pass
self._last_tap = False

@property
def double_tap(self):
"""True once after a double tap.
def tapped(self):
"""True once after a tap detection. use cpx.detect_taps to assign single (1) or double (2) tap

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

Quickly tap the CPX twice to double-tap.
Quickly tap the CPX twice to double-tap, or tap once for single-tap

.. code-block:: python

from adafruit_circuitplayground.express import cpx

while True:
if cpx.double_tap:
print("Double tap!")
if cpx.tapped:
print("Tapped!")
"""
try:
tapped = self._lis3dh.tapped
Expand Down