Skip to content

Commit e87cfdd

Browse files
kattnitannewt
authored andcommitted
Acceleration implemented. (#11)
Sphinx docs added, conf.py updated, image included.
1 parent 4090101 commit e87cfdd

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

_static/accelerometer.jpg

692 KB
Loading

adafruit_circuitplayground/express.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import adafruit_lis3dh
12
import adafruit_thermistor
23
import analogio
34
import array
45
import audioio
56
import board
7+
import busio
68
import digitalio
79
import math
810
import neopixel
@@ -60,6 +62,32 @@ def __init__(self):
6062
self._touch_A6 = None
6163
self._touch_A7 = None
6264

65+
# Define acceleration:
66+
self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
67+
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19)
68+
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
69+
self._lis3dh._write_register_byte(adafruit_lis3dh.REG_CTRL5, 0b01001000)
70+
self._lis3dh._write_register_byte(0x2E, 0b10000000)
71+
72+
@property
73+
def acceleration(self):
74+
"""Obtain data from the x, y and z axes.
75+
76+
.. image :: /_static/accelerometer.jpg
77+
78+
This example prints the values. Try moving the board to see how the
79+
printed values change.
80+
81+
.. code-block:: python
82+
83+
from adafruit_circuitplayground.express import cpx
84+
85+
while True:
86+
x, y, z = cpx.acceleration
87+
print(x, y, z)
88+
"""
89+
return self._lis3dh.acceleration
90+
6391
@property
6492
def touch_A1(self):
6593
"""Detect touch on capacitive touch pad A1.

conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'NeoPixel': ('https://circuitpython.readthedocs.io/projects/neopixel/en/latest/', None)}
2121

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

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

0 commit comments

Comments
 (0)