Last active
December 1, 2018 21:27
-
-
Save mooware/9a14ccf4691da707b90a90bac650a1a7 to your computer and use it in GitHub Desktop.
Script for the Pi Hut 3D Xmas Tree
This file contains 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
from gpiozero import LEDBoard | |
from time import sleep | |
import random | |
tree = LEDBoard(*range(2, 28), pwm=True) | |
# first led is the top one in the star | |
tree[0].value = 0.6 | |
leds = range(1, len(tree)) | |
def startup(): | |
for bright in (0.25, 0.50, 0.75, 1.0): | |
for led in leds: | |
tree[led].value = bright | |
sleep(0.1) | |
for led in reversed(leds): | |
tree[led].off() | |
sleep(0.1) | |
def run(): | |
# each iteration, pick a few leds and give them random values | |
shuffle_leds = leds[:] | |
while True: | |
count = random.randint(4, len(shuffle_leds)) | |
random.shuffle(shuffle_leds) | |
leds_on = shuffle_leds[0:count] | |
leds_off = shuffle_leds[count:] | |
for led in leds_off: | |
tree[led].off() | |
for led in leds_on: | |
tree[led].value = random.randint(2, 7) / 10.0 | |
sleep(1) | |
if __name__ == '__main__': | |
try: | |
startup() | |
run() | |
finally: | |
tree[0].off() | |
for led in leds: | |
tree[led].off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment