Skip to content

Commit

Permalink
Add tree.on() to main entry point in tree.py, update readme and add t…
Browse files Browse the repository at this point in the history
…ry/except for KeyboardInterrupt
  • Loading branch information
bennuttall committed Dec 17, 2019
1 parent 71ce223 commit f1a0ff0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions examples/huecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 7 additions & 4 deletions examples/onebyone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 5 additions & 2 deletions examples/randomsparkles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 6 additions & 3 deletions examples/rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ def close(self):

if __name__ == '__main__':
tree = RGBXmasTree()

tree.on()

0 comments on commit f1a0ff0

Please sign in to comment.