Skip to content

Commit 11ca7a2

Browse files
kattnitannewt
authored andcommitted
Added shake detection (#15)
1 parent 17b5462 commit 11ca7a2

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

adafruit_circuitplayground/express.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ def acceleration(self):
8888
"""
8989
return self._lis3dh.acceleration
9090

91+
def shake(self):
92+
"""Detect when device is shaken.
93+
94+
.. image :: /_static/accelerometer.jpg
95+
:alt: Accelerometer
96+
97+
.. code-block:: python
98+
99+
from adafruit_circuitplayground.express import cpx
100+
101+
while True:
102+
if cpx.shake():
103+
print("Shake detected!")
104+
105+
The `shake_threshold` default is 30. Decreasing this number increases
106+
shake sensitivity, i.e. the code will return a shake detected more
107+
easily with a lower `shake_threshold`. Increasing it causes the opposite.
108+
`shake_threshold` requires a minimum value of 10 - 10 is the value when
109+
the board is not moving, therefore anything less than 10 will
110+
erroneously report a constant shake detected.
111+
112+
.. code-block:: python
113+
114+
from adafruit_circuitplayground.express import cpx
115+
116+
while True:
117+
if cpx.shake(shake_threshold=20):
118+
print("Shake detected more easily than before!")
119+
"""
120+
return self._lis3dh.shake()
121+
122+
91123
@property
92124
def touch_A1(self):
93125
"""Detect touch on capacitive touch pad A1.
@@ -323,7 +355,7 @@ def temperature(self):
323355
temperature_c = cpx.temperature
324356
temperature_f = temperature_c * 1.8 + 32
325357
print("Temperature celsius:", temperature_c)
326-
print("Temperature farenheit:", temperature_f)
358+
print("Temperature fahrenheit:", temperature_f)
327359
time.sleep(1)
328360
"""
329361
return self._temp.temperature

0 commit comments

Comments
 (0)