]> vault307.fbx.one Git - Sensory_Wall.git/blob - 5vLEDcontroller.py
more sensory wall projects
[Sensory_Wall.git] / 5vLEDcontroller.py
1 import us100, machine, neopixel, time
2 # TODO adjust pin #s to match soldered connections, adjust distance trigger, _thread?
3 btn=machine.Pin(15, machine.Pin.IN,machine.Pin.PULL_UP)
4 light=machine.Pin(1,machine.Pin.OUT)
5 np=neopixel.NeoPixel(machine.Pin(0), 96)
6 sensor=us100.US100UART(machine.UART(1))
7
8 distance=0
9 position=0
10 brightness=0.5
11 def measure():
12 global distance
13 distance=sensor.distance()
14 return distance
15
16
17 def clear():
18 for i in range(np.n):
19 np[i]=(0,0,0)
20 np.write()
21
22 def fade(): #pick color
23 for i in range(0,4 * 256,8):
24 for j in range(np.n):
25 if (i // 256) % 2 == 0:
26 val = i & 0xff
27 else:
28 val = 255 - (i & 0xff)
29 np[j] = (val, val, 0)
30 np.write()
31
32 #colorcycle, does start over, do only i actually care about that? probably
33 def wheel(pos):
34 if pos < 85:
35 return(pos*3,255-pos*3,0)
36 elif pos <170:
37 pos-=85
38 return(255-pos*3,0,pos*3)
39 else:
40 pos -=170
41 return(0,pos*3,255-pos*3)
42
43 def loop():
44 global position, brightness
45
46 for i in range(np.n):
47 hue=int(i*(255/np.n)+position)%256
48 color=wheel(hue)
49 color=tuple(int(val*brightness) for val in color)
50 np[(i+position)%np.n]=color
51 np.write()
52 position=(position +1)% np.n
53 time.sleep_ms(66)
54
55 def main():
56 try:
57 measure()
58 print(distance)
59 time.sleep_ms(25)
60 except Exception:
61 print("idk, something went wrong man")
62 pass
63 """
64 main loop, hell yeah! throw them built funcs here!
65 """
66
67 while True:
68
69 if btn.value()==0:
70 light.off()
71 fade()
72 clear()
73 else:
74 light.on()
75
76 main()
77 if distance<=250:
78 loop()
79 main()
80 elif distance>=251:
81 clear()
82 main()
83
84
85