-
Notifications
You must be signed in to change notification settings - Fork 71
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
@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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thank you!