Skip to content

Instantly share code, notes, and snippets.

@bazwilliams
Created January 3, 2018 11:12
Show Gist options
  • Save bazwilliams/95604257f0aeb178c9762b015d29024f to your computer and use it in GitHub Desktop.
Save bazwilliams/95604257f0aeb178c9762b015d29024f to your computer and use it in GitHub Desktop.
A mix of effects for the 3D Xmas Tree from the PiHut (https://thepihut.com/products/3d-xmas-tree-for-raspberry-pi)
from gpiozero import LEDBoard
from time import sleep
from signal import pause
treelights=[ 18, 5, 9, 11, 21, 10, 7, 12, 6, 1,14, 3, 20, 24, 13, 15,2, 17, 16, 23,8, 22, 4, 19 ]
treemap={ 1:4, 7:5, 16:6, 22:7, 6:8 , 14:9, 8:10, 21:11, 15:12, 3:13, 19:14, 2:1 5, 9:16, 10:17, 20:18, 18:19,17:20, 4:21, 24:22, 23:23, 13:
24, 5:25, 12:26, 11:27
}
groups= [
[ 18 ],
[ 5, 9, 11, 21],
[ 10, 7, 12, 6, 1, 14, 3 ],
[ 20, 24, 13, 15 , 2, 17, 16, 23 ],
[ 8, 22, 4, 19 ]
]
leds=LEDBoard(*range(4,28), pwm=True)
def labelToPin(l):
return treemap[l]
def toBoard(l):
return labelToPin(l)-4
def cascade():
for i in treelights:
sleep(0.1)
leds.on(toBoard(i))
for i in treelights:
sleep(0.1)
leds.off(toBoard(i))
def on():
leds.on()
def off():
leds.off()
def hoops():
for treelights in groups[:-1]:
for i in treelights:
leds.on(toBoard(i))
sleep(0.2)
for i in treelights:
leds.off(toBoard(i))
for treelights in reversed(groups[1:]):
for i in treelights:
leds.on(toBoard(i))
sleep(0.2)
for i in treelights:
leds.off(toBoard(i))
while(True):
cascade()
on();
sleep(0.5);
off();
sleep(0.5);
on();
sleep(0.5);
off();
sleep(0.5);
hoops();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment