Skip to content

Acceleration implemented. #11

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
Oct 12, 2017
Merged
Show file tree
Hide file tree
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
Binary file added _static/accelerometer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import adafruit_lis3dh
import adafruit_thermistor
import analogio
import array
import audioio
import board
import busio
import digitalio
import math
import neopixel
Expand Down Expand Up @@ -60,6 +62,32 @@ def __init__(self):
self._touch_A6 = None
self._touch_A7 = None

# Define acceleration:
self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19)
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
self._lis3dh._write_register_byte(adafruit_lis3dh.REG_CTRL5, 0b01001000)
self._lis3dh._write_register_byte(0x2E, 0b10000000)

@property
def acceleration(self):
"""Obtain data from the x, y and z axes.

.. image :: /_static/accelerometer.jpg

This example prints the values. Try moving the board to see how the
printed values change.

.. code-block:: python

from adafruit_circuitplayground.express import cpx

while True:
x, y, z = cpx.acceleration
print(x, y, z)
"""
return self._lis3dh.acceleration

@property
def touch_A1(self):
"""Detect touch on capacitive touch pad A1.
Expand Down
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'NeoPixel': ('https://circuitpython.readthedocs.io/projects/neopixel/en/latest/', None)}

# Libraries we depend on but don't need for generating docs.
autodoc_mock_imports = ["board", "analogio", "digitalio", "neopixel", "adafruit_thermistor", "audioio", "touchio"]
autodoc_mock_imports = ["board", "analogio", "digitalio", "neopixel", "adafruit_thermistor", "audioio", "touchio", "adafruit_lis3dh", "busio"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down