Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mooware
Last active December 1, 2018 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooware/9a14ccf4691da707b90a90bac650a1a7 to your computer and use it in GitHub Desktop.
Save mooware/9a14ccf4691da707b90a90bac650a1a7 to your computer and use it in GitHub Desktop.
Script for the Pi Hut 3D Xmas Tree
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