-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneopixel_template.py
44 lines (32 loc) · 1.06 KB
/
neopixel_template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from neopixel.serial_library import write, WIDTH, HEIGHT
from neopixel.color_library import color_names, hsv2rgb
from time import time, sleep
import numpy as np
##############################################
# SET UP
##############################################
# initialize led array
leds = np.zeros((WIDTH, HEIGHT, 3))
# variables for drawing logic go here
# set a target framerate (max possible is around 60)
fps = 10
# variables for framerate logic
spf = 1 / fps
last_draw_time = time()
##############################################
# DRAW LOOP
##############################################
while True:
#----------------------------------------
# DRAWING LOGIC GOES HERE
#----------------------------------------
# TODO Delete the next line and make something cool
leds[:, :] = ((255 if time() % 2 < 1 else 0), 0, 0)
# END DRAWING LOGIC
# stay at target framerate
sleep_duration = last_draw_time + spf - time()
if sleep_duration > 0:
sleep(sleep_duration)
last_draw_time = time()
# update the matrix
write(leds)