Last active
February 7, 2021 18:35
-
-
Save shapr/0462480193250ecc0b0e71e9f21293a6 to your computer and use it in GitHub Desktop.
parsing bloom filter neopixel set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
import busio | |
import adafruit_trellism4 | |
import adafruit_adxl34x | |
import supervisor | |
# Set up Trellis and accelerometer | |
trellis = adafruit_trellism4.TrellisM4Express(rotation=0) | |
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) | |
sensor = adafruit_adxl34x.ADXL345(i2c) | |
#define colors | |
black = (0,0,0) | |
red = (255,0,0) | |
green = (0,255,0) | |
yellow = (255,255,0) | |
off = (16,16,64) | |
# enable tap to clear | |
sensor.enable_tap_detection(threshold=50) | |
brightness = 1.0 | |
trellis.pixels.fill((16,16,64)) | |
# trellis.pixels.brightness(1) # full brightness on the LEDs, values go from 0 - 1, 0.3 is 30% brightness | |
pixlsh = [[x,y] for x in range(trellis.pixels.width) for y in range(trellis.pixels.height) ] | |
pixlsw = [[x,y] for y in range(trellis.pixels.height) for x in range(trellis.pixels.width) ] | |
def linear_to_pair(n): | |
ival = int(n) | |
x = ival % trellis.pixels.width | |
y = ival // trellis.pixels.width | |
return (x,y) | |
def countup(color,delay=0.01): | |
#[setloc(x,y,color) for x in range(trellis.pixels.width) for y in range(trellis.pixels.height)] | |
[setloc(xy[0],xy[1],color,delay) for xy in pixlsh] | |
[setloc(xy[0],xy[1],color,delay) for xy in pixlsw] | |
def setloc(x,y,color,delay): | |
trellis.pixels[x,y] = color | |
time.sleep(delay) | |
def color(c): | |
trellis.pixels.fill(c) | |
def color_from_input(): | |
data = input().strip() | |
for l in data.split(","): | |
if l[0] == "r": | |
color = red | |
elif l[0] == "g": | |
color = green | |
elif l[0] == "y": | |
color = yellow | |
trellis.pixels[linear_to_pair(l[1:])] = color | |
while True: | |
pressed = trellis.pressed_keys | |
if pressed: | |
button_x_value = pressed[0][0] # first element of the list, first element of the x,y pair, should be 0-7 | |
brightness = (button_x_value + 3) / 10 | |
trellis.pixels.brightness = brightness | |
print("set trellis brightness to",brightness) | |
time.sleep(0.1) | |
if supervisor.runtime.serial_bytes_available: | |
color_from_input() | |
# check tap, no colors when detected | |
if sensor.events['tap']: | |
countup((16,16,64)) | |
countup((5,5,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment