]> vault307.fbx.one Git - Sensory_Wall.git/blob - LEDstripbreathe.py
more sensory wall projects
[Sensory_Wall.git] / LEDstripbreathe.py
1 import machine, neopixel, time
2 np=neopixel.NeoPixel(machine.Pin(0), 96)
3
4 n=np.n
5
6 position=0
7 brightness=0.5
8
9 def fade(np):
10 for i in range(0, 4 * 256, 8):
11 for j in range(n):
12 if (i // 256) % 2 == 0:
13 val = i & 0xff
14 else:
15 val = 255 - (i & 0xff)
16 np[j] = (val, val, 0)
17 np.write()
18
19 def bounce(np):
20 for i in range(4 * n):
21 for j in range(n):
22 np[j] = (0, 0, 128)
23 if (i // n) % 2 == 0:
24 np[i % n] = (0, 128, 128)
25 else:
26 np[n - 1 - (i % n)] = (0, 128, 128)
27 np.write()
28 time.sleep_ms(60)
29
30 def clear():
31 for i in range(n):
32 np[i] = (0, 0, 0)
33 np.write()
34
35 def wheel(pos):
36 if pos < 85:
37 return(pos*3,255-pos*3,0)
38 elif pos <170:
39 pos-=85
40 return(255-pos*3,0,pos*3)
41 else:
42 pos -=170
43 return(0,pos*3,255-pos*3)
44
45 def loop():
46 global position, brightness
47
48 for i in range(np.n):
49 hue=int(i*(255/np.n)+position)%256
50 color=wheel(hue)
51 color=tuple(int(val*brightness) for val in color)
52 np[(i+position)%np.n]=color
53 np.write()
54 position=(position +1)% np.n
55 #print(position)
56 time.sleep_ms(200)
57
58 def antiloop():
59 global position, brightness
60
61 for i in range(np.n):
62 hue=int(-i*(255/np.n)-position)%256
63 color=wheel(hue)
64 color=tuple(int(val*brightness) for val in color)
65 np[(i-position)%np.n]=color
66 np.write()
67 position=(position +1)% np.n
68 #print(position,"anti")
69 time.sleep_ms(200)
70
71
72 while True:
73 for i in range(np.n):
74 loop()
75 for i in range(np.n):
76 antiloop()