From 014dc3f191db69e580dfb7c87e968ea66020b26d Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 13 Dec 2015 16:01:30 +0000 Subject: [PATCH] Initial commit of Xmas tree --- .gitignore | 47 ++++++++ xmas_tree/README.txt | 19 +++ xmas_tree/example_1.py | 32 +++++ xmas_tree/example_2.py | 35 ++++++ xmas_tree/example_3.py | 32 +++++ xmas_tree/example_4.py | 35 ++++++ xmas_tree/example_5.py | 42 +++++++ xmas_tree/example_bicolour.py | 36 ++++++ xmas_tree/example_twin.py | 28 +++++ xmas_tree/tree.py | 204 ++++++++++++++++++++++++++++++++ xmas_tree/tree.pyc | Bin 0 -> 3999 bytes xmas_tree/tree2.py | 212 ++++++++++++++++++++++++++++++++++ xmas_tree/tree2.pyc | Bin 0 -> 4340 bytes xmas_tree/twin_random.py | 19 +++ 14 files changed, 741 insertions(+) create mode 100644 .gitignore create mode 100644 xmas_tree/README.txt create mode 100644 xmas_tree/example_1.py create mode 100644 xmas_tree/example_2.py create mode 100644 xmas_tree/example_3.py create mode 100644 xmas_tree/example_4.py create mode 100644 xmas_tree/example_5.py create mode 100644 xmas_tree/example_bicolour.py create mode 100644 xmas_tree/example_twin.py create mode 100644 xmas_tree/tree.py create mode 100644 xmas_tree/tree.pyc create mode 100644 xmas_tree/tree2.py create mode 100644 xmas_tree/tree2.pyc create mode 100644 xmas_tree/twin_random.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d99462 --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +*~ + +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 +__pycache__ + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# IPython +.ipynb* + +# Sublime text +*.sublime-workspace + +# Logs +*.log diff --git a/xmas_tree/README.txt b/xmas_tree/README.txt new file mode 100644 index 0000000..27ea5fa --- /dev/null +++ b/xmas_tree/README.txt @@ -0,0 +1,19 @@ +To get started with your GPIO Xmas Tree for the +Raspberry Pi, type the following at the command prompt: + +sudo python example_1.py + +You can then try the other examples: + +example_1.py : each LED on in turn +example_2.py : several LEDs on at once +example_3.py : one LED off each time, all the others on +example_4.py : all LEDs flashing on and off simultaneously +example_5.py : random LEDs +example_bicolour : an example with the Kickstarter bicolour LED + +For bicolour example, make sure you edit tree.py and set +bicolour_fitted to True. + +Please share your own code! Go to www.pocketmoneytronics.co.uk +or follow us on Twitter @pocketmoneytron diff --git a/xmas_tree/example_1.py b/xmas_tree/example_1.py new file mode 100644 index 0000000..7ea6708 --- /dev/null +++ b/xmas_tree/example_1.py @@ -0,0 +1,32 @@ +import tree + +# Some constants to identify each LED +L0 = 1 +L1 = 2 +L2 = 4 +L3 = 8 +L4 = 16 +L5 = 32 +L6 = 64 +ALL = 1+2+4+8+16+32+64 +NO_LEDS = 0 + +tree.setup() # you must always call setup() first! + +# Pattern: flash each LED in turn + +for i in range(5): # repeat 5 times + tree.leds_on_and_wait(L0, 0.3) # LED 0 on for 0.3 seconds + tree.leds_on_and_wait(L1, 0.3) # LED 1 on for 0.3 seconds + tree.leds_on_and_wait(L2, 0.3) # etc. + tree.leds_on_and_wait(L3, 0.3) + tree.leds_on_and_wait(L4, 0.3) + tree.leds_on_and_wait(L5, 0.3) + tree.leds_on_and_wait(L6, 0.3) + + +tree.all_leds_off() # extinguish all LEDs + +# All done! +tree.cleanup() # call cleanup() at the end + diff --git a/xmas_tree/example_2.py b/xmas_tree/example_2.py new file mode 100644 index 0000000..c8297f6 --- /dev/null +++ b/xmas_tree/example_2.py @@ -0,0 +1,35 @@ +import tree + +# Some constants to identify each LED +L0 = 1 +L1 = 2 +L2 = 4 +L3 = 8 +L4 = 16 +L5 = 32 +L6 = 64 +ALL = 1+2+4+8+16+32+64 +NO_LEDS = 0 + +tree.setup() # you must always call setup() first! + +# Pattern: two or three LEDs are on at the same time. +# Note that each pair is on for 0.4 seconds + +for i in range(7): # repeat the pattern 7 times + tree.leds_on_and_wait(L1+L4, 0.4) # LED 1 and LED 4 + tree.leds_on_and_wait(L5+L3+L0, 0.4) # LEDs 5, 3 and 0 + tree.leds_on_and_wait(L2+L6, 0.4) # LEDs 2 and 6 + tree.leds_on_and_wait(L5+L3+L0, 0.4) # LEDs 5, 3 and 0 + + +tree.all_leds_off() # extinguish all LEDs + +# All done! +tree.cleanup() # call cleanup() at the end + + + + + + diff --git a/xmas_tree/example_3.py b/xmas_tree/example_3.py new file mode 100644 index 0000000..a02222e --- /dev/null +++ b/xmas_tree/example_3.py @@ -0,0 +1,32 @@ +import tree + +# Some constants to identify each LED +L0 = 1 +L1 = 2 +L2 = 4 +L3 = 8 +L4 = 16 +L5 = 32 +L6 = 64 +ALL = 1+2+4+8+16+32+64 +NO_LEDS = 0 + +tree.setup() # you must always call setup() first! + +# Pattern: all LEDs illuminated except for one each time + +for i in range(3): # repeat 3 times + tree.leds_on_and_wait(ALL-L0, 0.5) # all on except for LED 0 + tree.leds_on_and_wait(ALL-L1, 0.5) # all on except for LED 1 + tree.leds_on_and_wait(ALL-L2, 0.5) # etc. + tree.leds_on_and_wait(ALL-L3, 0.5) + tree.leds_on_and_wait(ALL-L4, 0.5) + tree.leds_on_and_wait(ALL-L5, 0.5) + tree.leds_on_and_wait(ALL-L6, 0.5) + + +tree.all_leds_off() # extinguish all LEDs + +# All done! +tree.cleanup() # call cleanup() at the end + diff --git a/xmas_tree/example_4.py b/xmas_tree/example_4.py new file mode 100644 index 0000000..40d5571 --- /dev/null +++ b/xmas_tree/example_4.py @@ -0,0 +1,35 @@ +import tree +import time + +# Some constants to identify each LED +L0 = 1 +L1 = 2 +L2 = 4 +L3 = 8 +L4 = 16 +L5 = 32 +L6 = 64 +ALL = 1+2+4+8+16+32+64 +NO_LEDS = 0 + +tree.setup() # you must always call setup() first! + +# Two slightly different ways of flashing *all* LEDs on and off. + +# Way 1 +for i in range(3): # repeat 3 times + tree.leds_on_and_wait(ALL, 0.5) # all on for 0.5s + tree.leds_on_and_wait(NO_LEDS, 0.5) # all off for 0.5s + +# Way 2 +for i in range(3): # repeat 3 times + tree.leds_on_and_wait(ALL, 0.5) # all on for 0.5s + tree.all_leds_off() # extinguish all LEDs + time.sleep(0.5) # wait for 0.5s + + +tree.all_leds_off() # extinguish all LEDs + +# All done! +tree.cleanup() # call cleanup() at the end + diff --git a/xmas_tree/example_5.py b/xmas_tree/example_5.py new file mode 100644 index 0000000..843ce74 --- /dev/null +++ b/xmas_tree/example_5.py @@ -0,0 +1,42 @@ +import tree +import random + +# Some constants to identify each LED +L0 = 1 +L1 = 2 +L2 = 4 +L3 = 8 +L4 = 16 +L5 = 32 +L6 = 64 +ALL = 1+2+4+8+16+32+64 +NO_LEDS = 0 + +tree.setup() # you must always call setup() first! + +# Two ways of randomly illuminating LEDs (they do the +# same thing but Way 1 is easier to understand whilst +# Way 2 is a shorter piece of code). + +# Way 1 +for i in range(100): # repeat 100 times + random_led = random.randint(0, 6) + if (random_led == 0): tree.leds_on_and_wait(L0, 0.2) # D0 on for 0.2s + elif (random_led == 1): tree.leds_on_and_wait(L1, 0.2) # D1 on for 0.2s + elif (random_led == 2): tree.leds_on_and_wait(L2, 0.2) # D2 on for 0.2s + elif (random_led == 3): tree.leds_on_and_wait(L3, 0.2) # D3 on for 0.2s + elif (random_led == 4): tree.leds_on_and_wait(L4, 0.2) # D4 on for 0.2s + elif (random_led == 5): tree.leds_on_and_wait(L5, 0.2) # D5 on for 0.2s + elif (random_led == 6): tree.leds_on_and_wait(L6, 0.2) # D6 on for 0.2s + +# Way 2 +for i in range(100): # repeat 100 times + random_led = random.randint(0, 6) + tree.leds_on_and_wait(1<6rs zY4^-d_XJyOM;i>cNaTpPA|WE>04M&1h$D(PbI1XXh$|BOe%138ys#V5Gq0w)ey`rE z_g+=Kn#@1S#m^oc{h%d-CyU<|wD{*B9==9GkwYW*&G6Nd`U* z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