Skip to content

Added shake detection #15

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
Nov 29, 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
34 changes: 33 additions & 1 deletion adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,38 @@ def acceleration(self):
"""
return self._lis3dh.acceleration

def shake(self):
"""Detect when device is shaken.

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

.. code-block:: python

from adafruit_circuitplayground.express import cpx

while True:
if cpx.shake():
print("Shake detected!")

The `shake_threshold` default is 30. Decreasing this number increases
shake sensitivity, i.e. the code will return a shake detected more
easily with a lower `shake_threshold`. Increasing it causes the opposite.
`shake_threshold` requires a minimum value of 10 - 10 is the value when
the board is not moving, therefore anything less than 10 will
erroneously report a constant shake detected.

.. code-block:: python

from adafruit_circuitplayground.express import cpx

while True:
if cpx.shake(shake_threshold=20):
print("Shake detected more easily than before!")
"""
return self._lis3dh.shake()


@property
def touch_A1(self):
"""Detect touch on capacitive touch pad A1.
Expand Down Expand Up @@ -323,7 +355,7 @@ def temperature(self):
temperature_c = cpx.temperature
temperature_f = temperature_c * 1.8 + 32
print("Temperature celsius:", temperature_c)
print("Temperature farenheit:", temperature_f)
print("Temperature fahrenheit:", temperature_f)
time.sleep(1)
"""
return self._temp.temperature
Expand Down