Last active
November 27, 2023 12:40
-
-
Save soup-bowl/dae257518868e2ffcbb283ae2902aa67 to your computer and use it in GitHub Desktop.
LED Christmas Tree for Raspberry Pi - https://thepihut.com/products/3d-xmas-tree-for-raspberry-pi
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, PWMLED | |
from gpiozero.tools import random_values | |
from signal import pause | |
from time import time, sleep, strftime | |
class Tree(object): | |
def __init__(self): | |
self.active = False | |
self.tree = LEDBoard(*range(4,28),pwm=True) | |
self.star = PWMLED(2) | |
def is_on(self): | |
return self.active | |
def lights_twinkle(self): | |
self.star.on() | |
for led in self.tree: | |
led.source_delay = 0.1 | |
led.source = random_values() | |
self.active = True | |
def lights_off(self): | |
self.star.off() | |
for led in self.tree: | |
led.source_delay = 0.1 | |
led.source = [0] | |
self.active = False | |
def main(): | |
tree = Tree() | |
while True: | |
currenttime = int(strftime('%H')) | |
if currenttime > 7 and currenttime < 22: | |
tree.lights_twinkle() | |
else: | |
tree.lights_off() | |
sleep(30) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added to
.bash_aliases
:Breakdown:
Bartscript, die".python3
andpython3-gpiozero
are (usually) already installed).tree.py
file is located.>
means "redirect any output to this place", which is then set to null, so it goes straight into the trash.2>&1
means any error outputs (stderr) gets treated as regular output (stdout), which is subsequently trashed thanks to above.&
returns our Shell prompt back, despite the fact the script is still running.Altogether, it means the script will run but won't tell you the output, gives you command control back, and doesn't associate you shutting down your command window as the script dies too.
Adding this whole command to
.bash_aliases
on a bash system will mean each load-up of terminal will make the above command available.EDIT: Latest change means it'll run (very ineffectively) between 8 am and 11 pm.
EDIT2023: Adjusted to use Python 3 - Python 2 really shouldn't be used any more.