Skip to content

Instantly share code, notes, and snippets.

@benevpi
Created December 10, 2020 20:59
Show Gist options
  • Select an option

  • Save benevpi/a042548014bef469b9956487148cfd63 to your computer and use it in GitHub Desktop.

Select an option

Save benevpi/a042548014bef469b9956487148cfd63 to your computer and use it in GitHub Desktop.
import time
import board
import neopixel
try:
import urandom as random
except ImportError:
import random
bright_div = 20
numpix = 42 # Number of NeoPixels
pixpin = board.A1
# Pin where NeoPixels are connected
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False)
colors = [
[232, 100, 255], # Purple
[200, 200, 20], # Yellow
[30, 200, 200], # Blue
]
max_len=5
min_len = 2
#pixelnum, posn in flash, flash_len, direction
flashing = []
num_flashes = 5
for i in range(num_flashes):
pix = random.randint(0, numpix - 1)
col = random.randint(1, len(colors) - 1)
flash_len = random.randint(min_len, max_len)
flashing.append([pix, colors[col], flash_len, 0, 1])
strip.fill((0,0,0))
while True:
strip.show()
for i in range(num_flashes):
print(flashing[i])
pix = flashing[i][0]
brightness = (flashing[i][3]/flashing[i][2])
colr = (int(flashing[i][1][0]*brightness),
int(flashing[i][1][1]*brightness),
int(flashing[i][1][2]*brightness))
strip[pix] = colr
if flashing[i][2] == flashing[i][3]:
flashing[i][4] = -1
if flashing[i][3] == 0 and flashing[i][4] == -1:
pix = random.randint(0, numpix - 1)
col = random.randint(0, len(colors) - 1)
flash_len = random.randint(min_len, max_len)
flashing[i] = [pix, colors[col], flash_len, 0, 1]
flashing[i][3] = flashing[i][3] + flashing[i][4]
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment