From f1a0ff0c6e0207158de7cd8d490c9b98609508c9 Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Tue, 17 Dec 2019 19:05:33 +0000 Subject: [PATCH] Add tree.on() to main entry point in tree.py, update readme and add try/except for KeyboardInterrupt --- README.md | 6 ++++-- examples/huecycle.py | 7 +++++-- examples/onebyone.py | 11 +++++++---- examples/randomsparkles.py | 7 +++++-- examples/rgb.py | 9 ++++++--- tree.py | 2 ++ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0b92fa6..d847634 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ Start by downloading the xmas tree file. Open a terminal and type: wget https://bit.ly/2Lr9CT3 -O tree.py ``` +Test the tree by running `python3 tree.py` (or running it from an IDE like Mu, +Thonny or IDLE). All the lights should come on (white). + When you write your own Python code, make sure you keep this file in the same folder. @@ -20,8 +23,7 @@ using Raspbian Lite, you'll need to install gpiozero with: sudo apt install python3-gpiozero ``` -Open a Python shell or IDE (like Mu, Thonny or IDLE), import `RGBXmasTree` and -initialise your tree: +Open a Python shell or IDE, import `RGBXmasTree` and initialise your tree: ```python from tree import RGBXmasTree diff --git a/examples/huecycle.py b/examples/huecycle.py index 0946738..aa8bdf2 100644 --- a/examples/huecycle.py +++ b/examples/huecycle.py @@ -5,5 +5,8 @@ tree.color = Color('red') -while True: - tree.color += Hue(deg=1) +try: + while True: + tree.color += Hue(deg=1) +except KeyboardInterrupt: + tree.close() diff --git a/examples/onebyone.py b/examples/onebyone.py index c126f73..7c7d04e 100644 --- a/examples/onebyone.py +++ b/examples/onebyone.py @@ -5,7 +5,10 @@ colors = [Color('red'), Color('green'), Color('blue')] # add more if you like -while True: - for color in colors: - for pixel in tree: - pixel.color = color +try: + while True: + for color in colors: + for pixel in tree: + pixel.color = color +except KeyboardInterrupt: + tree.close() diff --git a/examples/randomsparkles.py b/examples/randomsparkles.py index de1e012..832e0a6 100644 --- a/examples/randomsparkles.py +++ b/examples/randomsparkles.py @@ -12,5 +12,8 @@ def random_color(): def random_colors(n): return [random_color() for i in range(n)] -while True: - tree.value = random_colors(25) +try: + while True: + tree.value = random_colors(25) +except KeyboardInterrupt: + tree.close() diff --git a/examples/rgb.py b/examples/rgb.py index 8576161..e48412d 100644 --- a/examples/rgb.py +++ b/examples/rgb.py @@ -5,6 +5,9 @@ colors = [Color('red'), Color('green'), Color('blue')] # add more if you like -while True: - for color in colors: - tree.color = color +try: + while True: + for color in colors: + tree.color = color +except KeyboardInterrupt: + tree.close() diff --git a/tree.py b/tree.py index 21ee6bc..861eb16 100644 --- a/tree.py +++ b/tree.py @@ -104,3 +104,5 @@ def close(self): if __name__ == '__main__': tree = RGBXmasTree() + + tree.on()