From: Neil Smith Date: Sun, 13 Dec 2015 16:01:30 +0000 (+0000) Subject: Initial commit of Xmas tree X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=014dc3f191db69e580dfb7c87e968ea66020b26d;p=pi-xmas.git Initial commit of Xmas tree --- 014dc3f191db69e580dfb7c87e968ea66020b26d 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<