Code library, CLI, and examples for the RGB Xmas Tree produced by PiHut.
This fork from the original PiHut code is totally independent and very grateful to @bennuttal for the initial work! Any bugs and mistakes herein are my own.
Install via pipx for easy access to the commandline interface:
pipx install rgbxmastreeYou can now use the rgbxmastree command and subcommands to run your tree!
To use the API in your own scripts and applications install via plain pip or your favourite project management tool:
pip install rgbxmastree
poetry add rgbxmastree
uv add rgbxmastreeOpen a Python shell or IDE, import RGBXmasTree and initialise your tree:
from rgbxmastree.tree import RGBXmasTree
tree = RGBXmasTree()You can set the colour of all the LEDs together using RGB values (all 0-1):
from rgbxmastree.tree import RGBXmasTree
tree = RGBXmasTree()
tree.color = (1, 0, 0)Alternatively you can use the colorzero library:
from rgbxmastree.tree import RGBXmasTree
from colorzero import Color
tree = RGBXmasTree()
tree.color = Color('red')You can write a loop to repeatedly cycle through red, green and blue:
from rgbxmastree.tree import RGBXmasTree
from time import sleep
tree = RGBXmasTree()
colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
for color in colors:
tree.color = color
sleep(1)You can also control each LED individually, for example turn each one red, one at a time:
from rgbxmastree.tree import RGBXmasTree
from time import sleep
tree = RGBXmasTree()
for pixel in tree:
pixel.color = (1, 0, 0)
sleep(1)To control a specific pixel, you can access it by its index number (0-24):
tree[0].color = (0, 1, 0)You can change the brightness from 0 to 1 - the default is 0.5. You can set this when initialising your tree:
from rgbxmastree.tree import RGBXmasTree
tree = RGBXmasTree(brightness=0.1)Alternatively, you can change it after initialisation:
from rgbxmastree.tree import RGBXmasTree
tree = RGBXmasTree()
tree.brightness = 0.1You'll find that 1 is extremely bright and even 0.1 is plenty bright enough if the tree is on your desk :)
Cycle through red, green and blue, changing all pixels together
Cycle through red, green and blue, changing pixel-by-pixel
Cycle through hues forever
Randomly sparkle all the pixels