From 41bf6c0e1a1482a18c3e5a3df4b9f0e1c4c36433 Mon Sep 17 00:00:00 2001 From: Kattni Date: Mon, 27 Nov 2017 15:55:00 -0500 Subject: [PATCH 1/2] Added shake detection --- adafruit_circuitplayground/express.py | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index c636086..97b8dd8 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -88,6 +88,39 @@ def acceleration(self): """ return self._lis3dh.acceleration + @property + 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 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 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. @@ -323,7 +356,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 From 8f06211d9b27754b5ab2a5b450139718fde77b4d Mon Sep 17 00:00:00 2001 From: Kattni Date: Tue, 28 Nov 2017 16:18:24 -0500 Subject: [PATCH 2/2] Updated with requested changes --- adafruit_circuitplayground/express.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index 97b8dd8..c6b170c 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -88,7 +88,6 @@ def acceleration(self): """ return self._lis3dh.acceleration - @property def shake(self): """Detect when device is shaken. @@ -100,8 +99,8 @@ def shake(self): from adafruit_circuitplayground.express import cpx while True: - if shake(): - print("Shake detected!") + 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 @@ -115,10 +114,10 @@ def shake(self): from adafruit_circuitplayground.express import cpx while True: - if shake(shake_threshold=20): - print("Shake detected more easily than before!") + if cpx.shake(shake_threshold=20): + print("Shake detected more easily than before!") """ - return self._lis3dh.shake + return self._lis3dh.shake() @property