Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created November 2, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckerego/9f3507c9d8d7bb07f0e6a5a1c3372010 to your computer and use it in GitHub Desktop.
Save deckerego/9f3507c9d8d7bb07f0e6a5a1c3372010 to your computer and use it in GitHub Desktop.
Multi-sensor Feedback with Circuit Playground Express
# Circuit Playground NeoPixel
import time
import board
import neopixel
import busio
import analogio
import digitalio
import simpleio
import adafruit_thermistor
import adafruit_lis3dh
# NeoPixels
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
# Light indicator
light = analogio.AnalogIn(board.LIGHT)
ambient_brightness = simpleio.map_range(light.value, 800, 60000, 0, 100) / 100
# Thermisotor
thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
# Accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
lis3dh.range = adafruit_lis3dh.RANGE_8_G
def animate(pixlist, color):
for index in range(10):
pixels[index] = color if index in pixlist else (0, 0, 0)
pixels.brightness = ambient_brightness
pixels.show()
def pixel_list():
x, y, z = lis3dh.acceleration
pixels = []
pixels = pixels + [1, 2, 3] if x >= 1.0 else pixels # Right
pixels = pixels + [6, 7, 8] if x <= -1.0 else pixels # Left
pixels = pixels + [0, 9] if y <= -1.0 else pixels # Up
pixels = pixels + [4, 5] if y >= 1.0 else pixels # Down
pixels = [] if z <= -1.0 else pixels # Back
return pixels
while True:
pixlist = pixel_list()
temperature_red = simpleio.map_range(thermistor.temperature, 16, 35, 0, 255)
animate(pixlist, (int(temperature_red), 0, 255))
time.sleep(0.1)
# Circuit Playground NeoPixel
import simpleio
import time
from adafruit_circuitplayground.express import cpx
led_brightness = cpx.light / 300
def animate(pixels, color):
for index in range(10):
cpx.pixels[index] = color if index in pixels else (0, 0, 0)
cpx.pixels.brightness = led_brightness
def pixel_list():
x, y, z = cpx.acceleration
pixels = []
pixels = pixels + [1, 2, 3] if x >= 1.0 else pixels # Right
pixels = pixels + [6, 7, 8] if x <= -1.0 else pixels # Left
pixels = pixels + [0, 9] if y <= -1.0 else pixels # Up
pixels = pixels + [4, 5] if y >= 1.0 else pixels # Down
pixels = [] if z <= -1.0 else pixels # Back
return pixels
while True:
pixels = pixel_list()
temperature_red = simpleio.map_range(cpx.temperature, 16, 35, 0, 255)
animate(pixels, (int(temperature_red), 0, 255))
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment