-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchristmasTreeLight.py
152 lines (139 loc) · 4.55 KB
/
christmasTreeLight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
#Endless Christmas Tree Light by Alexander Ochs - noxmiles.de
#based on code by Andrew Gale - pocketmoneytronics.co.uk
import tree
import random
import sys
# 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 # = 127
NO_LEDS = 0
# All pattern here
def pattern1(): # ascending
tree.leds_on_and_wait(L0, 0.5)
tree.leds_on_and_wait(L1, 0.5)
tree.leds_on_and_wait(L2, 0.5)
tree.leds_on_and_wait(L3, 0.5)
tree.leds_on_and_wait(L4, 0.5)
tree.leds_on_and_wait(L5, 0.5)
tree.leds_on_and_wait(L6, 0.5)
def pattern2(): # 2 or 3
tree.leds_on_and_wait(L1+L4, 0.5)
tree.leds_on_and_wait(L5+L3+L0, 0.5)
tree.leds_on_and_wait(L2+L6, 0.5)
tree.leds_on_and_wait(L5+L3+L0, 0.5)
def pattern3(): # blinking
tree.leds_on_and_wait(ALL, 0.5)
tree.leds_on_and_wait(NO_LEDS, 0.5)
def pattern4(): # ascending, yellow always on
tree.leds_on_and_wait(L0, 0.5)
tree.leds_on_and_wait(L0+L1, 0.5)
tree.leds_on_and_wait(L0+L2, 0.5)
tree.leds_on_and_wait(L0+L3, 0.5)
tree.leds_on_and_wait(L0+L4, 0.5)
tree.leds_on_and_wait(L0+L5, 0.5)
tree.leds_on_and_wait(L0+L6, 0.5)
def pattern5(): # filling
tree.leds_on_and_wait(L0, 0.5)
tree.leds_on_and_wait(L6, 0.5)
tree.leds_on_and_wait(L5, 0.5)
tree.leds_on_and_wait(L4, 0.5)
tree.leds_on_and_wait(L2, 0.5)
tree.leds_on_and_wait(L1, 0.5)
tree.leds_on_and_wait(L1+L0, 0.5)
tree.leds_on_and_wait(L1+L6, 0.5)
tree.leds_on_and_wait(L1+L5, 0.5)
tree.leds_on_and_wait(L1+L4, 0.5)
tree.leds_on_and_wait(L1+L2, 0.5)
tree.leds_on_and_wait(L1+L3, 0.5)
tree.leds_on_and_wait(L1+L3+L0, 0.5)
tree.leds_on_and_wait(L1+L3+L6, 0.5)
tree.leds_on_and_wait(L1+L3+L5, 0.5)
tree.leds_on_and_wait(L1+L3+L4, 0.5)
tree.leds_on_and_wait(L1+L3+L2, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L0, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L6, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L5, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4+L0, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4+L6, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4+L5, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4+L5+L0, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4+L5+L6, 0.5)
tree.leds_on_and_wait(L1+L3+L2+L4+L5+L6+L0, 0.5)
tree.leds_on_and_wait(NO_LEDS, 0.5)
tree.leds_on_and_wait(L1+L2+L3+L4+L5+L6+L0, 0.5)
tree.leds_on_and_wait(NO_LEDS, 0.5)
tree.leds_on_and_wait(L1+L2+L3+L4+L5+L6+L0, 0.5)
tree.leds_on_and_wait(NO_LEDS, 0.5)
tree.leds_on_and_wait(L1+L2+L3+L4+L5+L6+L0, 0.5)
tree.leds_on_and_wait(NO_LEDS, 0.5)
82,1 34%
def pattern6(): # falling
tree.leds_on_and_wait(L0, 0.5)
tree.leds_on_and_wait(L0+L6, 0.5)
tree.leds_on_and_wait(L0+L6+L5, 0.5)
tree.leds_on_and_wait(L6+L5+L4, 0.5)
tree.leds_on_and_wait(L5+L4+L2, 0.5)
tree.leds_on_and_wait(L4+L2+L3+L1, 0.5)
tree.leds_on_and_wait(L2+L3+L1, 0.5)
tree.leds_on_and_wait(L3+L1, 0.5)
tree.leds_on_and_wait(NO_LEDS, 0.5)
def pattern7(): # blinking, yellow always on
tree.leds_on_and_wait(L0, 0.5)
tree.leds_on_and_wait(ALL, 0.5)
def pattern8(): # random LED on
rand_led = random.randint(0, 6)
tree.leds_on_and_wait(1<<rand_led, 0.5) # == 2**rand_led
def pattern9(): # candle shine like
random_led = 0
for y in range(6):
random_led += 2**y * random.randint(0,1) * random.randint(0,1) # each LED choosen by 25%
random_time = random.randint(1,3) # time between 0.1 and 0.3s
tree.leds_on_and_wait(ALL - random_led, float(random_time)/10)
random_time = random.randint(1,15) #light time between 0.1 and 1.5s
tree.leds_on_and_wait(ALL, float(random_time)/10)
tree.setup()
print("Christmas Tree Light. To stop press CTRL + C")
while True:
try:
random_led = random.randint(1, 9)
# print random_led # just for information
if random_led == 1:
for y in range(4):
pattern1()
elif random_led == 2:
for y in range(4):
pattern2()
elif random_led == 3:
for y in range(10):
pattern3()
elif random_led == 4:
for y in range(4):
pattern4()
elif random_led == 5:
pattern5()
elif random_led == 6:
for y in range(2):
pattern6()
elif random_led == 7:
for y in range(5):
pattern7()
elif random_led == 8:
for y in range(20):
pattern8()
elif random_led == 9:
for y in range(20):
pattern9()
except KeyboardInterrupt:
tree.all_leds_off()
tree.cleanup()
sys.exit()
tree.all_leds_off()
tree.cleanup()