/xmas-tree-container

Drive The Pi Hut XMas tree from container

Primary LanguagePython

XMas Tree Container

Overview

Simple sample setup to drive the 3D Xmas Tree for Raspberry Pi from The Pi Hut using containers, either with balenaCloud or with Docker / Docker Compose

The code skeleton supports the original 3D Xmas Tree with red LED's as well as the latest one with addressable RGB LED's; the same container can be used on several device using the XMAS_TREE_TYPE environment variable to select the hardware or the LED animation scenario.

Included scenarios:

  • Original tree:
    • red
    • red-random: randomly sparkle pixels
  • RGB Tree:
    • rgb / rgb-rainbow: rainbow effect
    • rgb-cycle: cycle through red, green and blue, changing pixel-by-pixel
    • rgb-random: randomly sparkle all the pixels
    • rgb-random-half: randomly sparkle half of the pixels

Adding a scenario

You can easily add new animation scenarios by adding a function in xmas-tree.py and a new entry in the tree_map dictionary.

The function must accept an optional float delay parameter.

Usage

balenaCloud

Create a new application, provision a device and push this repository with the Balena CLI. E.g:

balena push <My XMas App>

If you are unfamiliar with balenaCloud, follow the steps described in Get started with Raspberry Pi.

Define a Device variable or a Device Service variable for you device named XMAS_TREE_TYPE with the value for your animation scenario (see above list).

Optionally define a XMAS_DELAY variable to change the speed of the animation. The meaning and default value for the delay is scenario dependant.

That's it!

When you change the value of a variable, your container will be automatically restarted and the new parameters.

If you make changes to xmas-tree.py, run balena push to rebuild the container and update your devices.

Docker / Docker Compose

If you prefer, you can use directly Docker and Docker Compose on your Pi.

Copy the .env-distr file to .env and configure:

  • MACHINE_NAME: your Raspberry Pi version
  • XMAS_TREE_TYPE: the selected tree type / animation scenario
  • XMAS_DELAY (optional): change the speed of the animation. The meaning and default value for the delay is scenario dependant.

Build the container:

docker compose build

Run the container:

docker compose up

To change the scenario or the delay, edit the .env file, bring you container down and up again.

Changes in xmas-tree.py will require a new build.

License

The code in this repository contains sample code from The Pi Hut which does not specify any licence and by default is All Rights Reserved.