-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffect_snake.py
35 lines (32 loc) · 1.31 KB
/
effect_snake.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
# sample effect
# you can add your own effects by creating an effect_<name>.py file
# with an 'execute(leds, properties) function as shown below
import time
# it's a good idea to have some default properties
defaults = { "length": 5, "color": [255, 0, 0], "delay": 0.1 }
# the 'execute' method is executed when a POST request on .../effects/<name> is received
# this method should return when the effect is done, as long a one effect is executed, all
# other received effect requests get queued (until the effect_queue is full)
# properties contains the data from the POST request
def execute(leds, properties):
# the user might have forgotten a property so merge with the defaults
p = dict(defaults.items() + properties.items())
length = p["length"]
# the special key 'num_leds' is always set and contains the amount of LEDs
# as configured in the led_server.py
max_leds = p["num_leds"]
start = p["start_offset"]
color = p["color"]
delay = p["delay"]
leds.clear()
leds.show()
for i in range(start, max_leds + length):
if i < max_leds:
leds.set_pixel_rgb(i, *color)
if i >= length:
leds.set_pixel_rgb(i - length, 0, 0, 0)
leds.show()
time.sleep(delay)
# when the effect is done, clear all LEDs
leds.clear()
leds.show()