From 5246fee2d073b154fa61768981f8c8e90afe77cd Mon Sep 17 00:00:00 2001 From: Harold Dyson Date: Mon, 10 Dec 2018 21:27:31 +0000 Subject: [PATCH 1/2] Example commit to experiment with --- Blinky_lights/tree.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) mode change 100644 => 100755 Blinky_lights/tree.py diff --git a/Blinky_lights/tree.py b/Blinky_lights/tree.py old mode 100644 new mode 100755 index d253c00..4413187 --- a/Blinky_lights/tree.py +++ b/Blinky_lights/tree.py @@ -1,22 +1,27 @@ +#!/usr/bin/env python # Simple demo of of the WS2801/SPI-like addressable RGB LED lights. -import time import pixel_strings_fncs as q - + # Configure the count of pixels: PIXEL_COUNT = 46 -top = [x+37 for x in range(9)] -middle = [x+22 for x in range(11)] -bottom = range(18) -pixels = q.initialise_pixels(PIXEL_COUNT) +def set_tree(): + '''Insert docstring here''' + top = range(37, 46) + middle = range(22, 33) + bottom = range(18) + + pixels = q.initialise_pixels(PIXEL_COUNT) -top_state = q.make_rainbow_state(top) -middle_state = q.make_rainbow_state(middle) -bottom_state = q.make_rainbow_state(bottom) -q.set_state(pixels, top, top_state) -q.set_state(pixels, middle, middle_state) -q.set_state(pixels, bottom, bottom_state) -pixels.show() + top_state = q.make_rainbow_state(top) + middle_state = q.make_rainbow_state(middle) + bottom_state = q.make_rainbow_state(bottom) + q.set_state(pixels, top, top_state) + q.set_state(pixels, middle, middle_state) + q.set_state(pixels, bottom, bottom_state) + pixels.show() +if __name__ == '__main__': + set_tree() From 17315aeda5296248938e62c707232c5112da7cb0 Mon Sep 17 00:00:00 2001 From: Harold Dyson Date: Mon, 10 Dec 2018 22:02:27 +0000 Subject: [PATCH 2/2] Added proof of concept flask wrapper. --- Blinky_lights/tree.py | 52 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/Blinky_lights/tree.py b/Blinky_lights/tree.py index 4413187..1fee7bf 100755 --- a/Blinky_lights/tree.py +++ b/Blinky_lights/tree.py @@ -1,25 +1,59 @@ #!/usr/bin/env python # Simple demo of of the WS2801/SPI-like addressable RGB LED lights. +from flask import Flask +# To install and run flask: +# $ pip install Flask +# $ FLASK_APP=tree.py flask run +# and then point a webbrowser to the Pi's IP address, port 5000 and page +# top/colour, middle/colour, bottom/colour (i.e. +# http://aaa.bbb.ccc.ddd:5000/top/RGB). Not sure how you're expressing RGB, +# but it should be the same in the URL as in the q.make_colour_state +# function. Dynamic DNS and a proper webserver (e.g. apache) needed for more +# than basic testing! I can help set this up. Ideally, you'd run a browser +# locally on the pi, in which case you can use http://localhost:5000/top/RGB. +# We should probably show something in the browser too. + import pixel_strings_fncs as q + +app = Flask(__name__) # Configure the count of pixels: PIXEL_COUNT = 46 +TOP = range(37, 46) +MIDDLE = range(22, 33) +BOTTOM = range(18) def set_tree(): '''Insert docstring here''' - top = range(37, 46) - middle = range(22, 33) - bottom = range(18) + pixels = q.initialise_pixels(PIXEL_COUNT) + top_state = q.make_rainbow_state(TOP) + middle_state = q.make_rainbow_state(MIDDLE) + bottom_state = q.make_rainbow_state(BOTTOM) + q.set_state(pixels, TOP, top_state) + q.set_state(pixels, MIDDLE, middle_state) + q.set_state(pixels, BOTTOM, bottom_state) + pixels.show() + + +@app.route('/top/') +def set_top(colour): + pixels = q.initialise_pixels(PIXEL_COUNT) + q.set_state_rgb(pixels, TOP, q.make_colour_state(TOP, colour)) + pixels.show() + +@app.route('/middle/') +def set_middle(colour): pixels = q.initialise_pixels(PIXEL_COUNT) + q.set_state_rgb(pixels, MIDDLE, q.make_colour_state(MIDDLE, colour)) + pixels.show() + - top_state = q.make_rainbow_state(top) - middle_state = q.make_rainbow_state(middle) - bottom_state = q.make_rainbow_state(bottom) - q.set_state(pixels, top, top_state) - q.set_state(pixels, middle, middle_state) - q.set_state(pixels, bottom, bottom_state) +@app.route('/bottom/') +def set_bottom(colour): + pixels = q.initialise_pixels(PIXEL_COUNT) + q.set_state_rgb(pixels, BOTTOM, q.make_colour_state(BOTTOM, colour)) pixels.show()