Skip to content

Instantly share code, notes, and snippets.

@rysk-t
Created June 12, 2025 03:09
Show Gist options
  • Save rysk-t/e57b1fab4be4c8060504e9a4984d97a6 to your computer and use it in GitHub Desktop.
Save rysk-t/e57b1fab4be4c8060504e9a4984d97a6 to your computer and use it in GitHub Desktop.
import time
import busio
import board
import adafruit_lis3dh
from adafruit_motor import servo
z_pool = [0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,]
# Setup accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
sensor = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
i = 0
last_time = time.monotonic()
start_time = last_time*1
while True:
x, y, z = sensor.acceleration
z_pool[i % 30] = z
i += 1
z_avg = sum(z_pool) / 30
cur_time = time.monotonic()
if (cur_time - last_time) > 1:
print(cur_time-start_time, x,y,z,str(z_avg))
last_time = time.monotonic()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment