Adafruit_CircuitPython_ADXL34x/examples/adxl34x_motion_detection_test.py
2020-03-16 16:39:26 -04:00

21 lines
567 B
Python

import time
import board
import busio
import adafruit_adxl34x
i2c = busio.I2C(board.SCL, board.SDA)
# For ADXL343
accelerometer = adafruit_adxl34x.ADXL343(i2c)
# For ADXL345
# accelerometer = adafruit_adxl34x.ADXL345(i2c)
accelerometer.enable_motion_detection()
# alternatively you can specify the threshold when you enable motion detection for more control:
# accelerometer.enable_motion_detection(threshold=10)
while True:
print("%f %f %f" % accelerometer.acceleration)
print("Motion detected: %s" % accelerometer.events["motion"])
time.sleep(0.5)