Circuit Playground Express Motion Detection with Circuit Python
Another built-in feature of the Circuit Playground Express is the accelerometer - paired with the Neopixels makes for a nice visual spirit level!
Here we output the X, Y and Z to the console so you can add more features to the code, but for now it simply lights up all the RGB Leds using the Fill command :)
import time
import board
import adafruit_lis3dh
import busio
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.5)
pixels.fill((80, 0, 150))
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19)
lis3dh.range = adafruit_lis3dh.RANGE_8_G
while True:
x, y, z = lis3dh.acceleration
print((x, y, z))
if(x > 1):
pixels.fill((0, 0, 150))
elif(x < 0):
pixels.fill((80, 0, 0))
else:
pixels.fill((80, 0, 150))
time.sleep(0.1)
