Giter VIP home page Giter VIP logo

rgbxmastree's Introduction

rgbxmastree

Code examples for the RGB Xmas Tree

Getting started

Start by downloading the xmas tree file. Open a terminal and type:

wget https://bit.ly/2Lr9CT3 -O tree.py

Install the colorzero package

sudo apt update
sudo apt install python-colorzero python3-colorzero

When you write your own Python code, make sure you keep this file in the same folder.

Open a Python shell or IDE (like Mu, Thonny or IDLE) and import RGBXmasTree:

from tree import RGBXmasTree

Initialise your tree:

from tree import RGBXmasTree

tree = RGBXmasTree()

Change the brightness

You can change the brightness from 0 to 1 - the default is 0.5:

from tree import RGBXmasTree

tree = RGBXmasTree(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 :)

Change the colour

You can set the colour of all the LEDs together using RGB values (all 0-1):

from tree import RGBXmasTree

tree = RGBXmasTree()

tree.color = (1, 0, 0)

Alternatively you can use the colorzero library:

from 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 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 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)

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

Cheerlights (via HTTP) by ajgbarnes

Subscribes to the colour changes from Cheerlights. CheerLights is an “Internet of Things” project created by Hans Scharler that allows people's lights all across the world to synchronize to one color set by Twitter. To change the colour, from your Twitter account send a message to @Cheerlights using on of the valid colours described on this page https://cheerlights.com/cheerlights-api/

To run this

python3 cheerlights-http.py

Cheerlights History (via HTTP) by ajgbarnes

Similar to Cheerlights (via HTTP) but lights a new led / bauble each time a new colour comes through

To run this

python3 cheerlights-history-http.py

Cheerlights (via MQTT) by ajgbarnes

Similar to Cheerlights (via HTTP) but subscribes to the MQTT feed so you never miss a colour update. MQTT queues them so you get an update every 30 seconds rather than rapidly as they happen.

To run this

pip3 install paho-mqtt
python3 cheerlights-mqtt.py

To autostart this on boot of the Raspberry Pi

sudo pip3 install paho-mqtt
python3 /path/to/files/cheerlights.py &

Cheerlights History (via MQTT) by ajgbarnes

Similar to Cheerlights (via MQTT) but lights a new led / bauble each time a new colour comes through

To run this

python3 cheerlights-history-mqtt.py

rgbxmastree's People

Contributors

bennuttall avatar

Stargazers

Rupert Wilson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.