Skip to main content

API and commands for interacting with the Pi Hut RGB Xmas Tree.

Project description

rgbxmastree

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.

Getting started

Install via pipx for easy access to the commandline interface:

pipx install rgbxmastree

You 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 rgbxmastree

Initialising a tree instance

Open a Python shell or IDE, import RGBXmasTree and initialise your tree:

from rgbxmastree.tree import RGBXmasTree

tree = RGBXmasTree()

Change the colour

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)

Individual control

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)

Change the brightness

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.1

You'll find that 1 is extremely bright and even 0.1 is plenty bright enough if the tree is on your desk :)

Examples

RGB cycle

Cycle through red, green and blue, changing all pixels together

One-by-one

Cycle through red, green and blue, changing pixel-by-pixel

Hue cycle

Cycle through hues forever

Random sparkles

Randomly sparkle all the pixels

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rgbxmastree-0.2.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rgbxmastree-0.2.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file rgbxmastree-0.2.1.tar.gz.

File metadata

  • Download URL: rgbxmastree-0.2.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.16

File hashes

Hashes for rgbxmastree-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6d3b37485b2dae3db669d6ce072a9e705f7a4b0a60dd4e8bb9f83ba5da78528a
MD5 1a362f91ffedd71d94c054e9d3454644
BLAKE2b-256 a1f6f4e041b39f51c36bb6be4f4724fa1a2f450cb489283e53d31a5633c89b41

See more details on using hashes here.

File details

Details for the file rgbxmastree-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rgbxmastree-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 970e0a3beae8d37b92b0a351aeed2b11f506aa76c141149f0fdce3a760857db2
MD5 07be9b3dba235ffa992f11d8a6567260
BLAKE2b-256 f3d1fca0a4f13b1a1e89cf24a75d7e5e5ec94eb3c51f8589e3b532fbf1f16c14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page