Skip to content

Commit 405fa8c

Browse files
authored
Merge pull request #39 from kattni/example-update
Example update
2 parents 9939f9e + 6473044 commit 405fa8c

File tree

3 files changed

+13
-41
lines changed

3 files changed

+13
-41
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
155155
# (useful for modules/projects where namespaces are manipulated during runtime
156156
# and thus existing member attributes cannot be deduced by static analysis. It
157157
# supports qualified module names, as well as Unix pattern matching.
158-
ignored-modules=
158+
ignored-modules=board
159159

160160
# Show a hint with possible names when a member name was not found. The aspect
161161
# of finding the hint is based on edit distance.

examples/lis3dh_simpletest.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
1-
# Accelerometer example.
2-
# Reads the accelerometer x, y, z values and prints them every tenth of a second.
3-
# Open the serial port after running to see the output printed.
4-
# Author: Tony DiCola
51
import time
62
import board
3+
import digitalio
74
import busio
85
import adafruit_lis3dh
96

10-
11-
# Uncomment _one_ of the hardware setups below depending on your wiring:
12-
137
# Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available;
148
# otherwise check I2C pins.
15-
# pylint: disable=no-member
169
if hasattr(board, 'ACCELEROMETER_SCL'):
1710
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
18-
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
11+
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
12+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
1913
else:
2014
i2c = busio.I2C(board.SCL, board.SDA)
21-
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
22-
23-
# Software I2C setup:
24-
#import bitbangio
25-
#i2c = bitbangio.I2C(board.SCL, board.SDA)
26-
#lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
15+
int1 = digitalio.DigitalInOut(board.D9) # Set this to the correct pin for the interrupt!
16+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
2717

2818
# Hardware SPI setup:
29-
#import busio
30-
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
31-
#cs = busio.DigitalInOut(board.D6) # Set to appropriate CS pin!
32-
#lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs)
19+
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
20+
# cs = digitalio.DigitalInOut(board.D9) # Set to appropriate CS pin!
21+
# lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs)
3322

3423

3524
# Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G).
@@ -40,6 +29,6 @@
4029
# Read accelerometer values (in m / s ^ 2). Returns a 3-tuple of x, y,
4130
# z axis values. Divide them by 9.806 to convert to Gs.
4231
x, y, z = [value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration]
43-
print('x = {}G, y = {}G, z = {}G'.format(x, y, z))
32+
print("x = %0.3f G, y = %0.3f G, z = %0.3f G" % (x, y, z))
4433
# Small delay to keep things responsive but give time for interrupt processing.
4534
time.sleep(0.1)

examples/tap.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
1-
# Tap detection example.
2-
# Will loop forever printing when a single or double click is detected.
3-
# Open the serial port after running to see the output printed.
4-
# Author: Tony DiCola
1+
import time
52
import board
63
import busio
74
import digitalio
85
import adafruit_lis3dh
96

10-
11-
# Uncomment _one_ of the hardware setups below depending on your wiring:
12-
137
# Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available;
148
# otherwise check I2C pins.
15-
# pylint: disable=no-member
169
if hasattr(board, 'ACCELEROMETER_SCL'):
1710
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
1811
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
1912
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
2013
else:
2114
i2c = busio.I2C(board.SCL, board.SDA)
22-
int1 = digitalio.DigitalInOut(board.D10) # Set this to the correct pin for the interrupt!
15+
int1 = digitalio.DigitalInOut(board.D9) # Set this to the correct pin for the interrupt!
2316
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
2417

25-
# Software I2C setup:
26-
# import bitbangio
27-
# i2c = bitbangio.I2C(board.SCL, board.SDA)
28-
# lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
29-
30-
# Hardware SPI setup:
31-
# import busio
32-
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
33-
# cs = busio.DigitalInOut(board.D6) # Set to appropriate CS pin!
34-
# lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs)
35-
3618
# Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G).
3719
lis3dh.range = adafruit_lis3dh.RANGE_8_G
3820

@@ -52,3 +34,4 @@
5234
while True:
5335
if lis3dh.tapped:
5436
print('Tapped!')
37+
time.sleep(0.01)

0 commit comments

Comments
 (0)