]> vault307.fbx.one Git - Sensory_Wall.git/blob - distanceTest.py
more sensory wall projects
[Sensory_Wall.git] / distanceTest.py
1 import machine
2 import utime
3 import us100
4
5 <<<<<<< HEAD
6 uart = machine.UART(0)
7 sensor = us100.US100UART(uart)
8
9 Ygem=machine.Pin(10,machine.Pin.OUT)
10 Bgem=machine.Pin(16,machine.Pin.OUT)
11 plant=machine.Pin(18,machne.Pin.OUT)
12
13 =======
14 uart = machine.UART(1)
15 sensor = us100.US100UART(uart)
16
17 distance=0
18
19 Ygem=machine.Pin(10,machine.Pin.OUT)
20 Bgem=machine.Pin(16,machine.Pin.OUT)
21 plant=machine.Pin(18,machine.Pin.OUT)
22
23 Ygem.off();Bgem.off();plant.off()
24
25 def measure():
26 global distance
27 distance=sensor.distance()
28 return distance
29
30 def analyze():
31 if distance <=500 and distance>=350:
32 Ygem.on()
33 Bgem.off()
34 plant.off()
35 return
36 elif distance <=350 and distance >=150:
37 plant.on()
38 Ygem.off()
39 return
40 elif distance <=150 and distance >75:
41 Bgem.on()
42 plant.off()
43 Ygem.on()
44 return
45 elif distance <=75:
46 Bgem.off()
47 plant.on()
48 Ygem.on()
49 return
50 else:
51 Bgem.off()
52 plant.off()
53 Ygem.off()
54 return
55
56 while True:
57 try:
58 measure()
59 print(distance)
60 analyze()
61 utime.sleep_ms(50)
62 except Exception: #catches error if sensor is covered, simply passes that cycle
63 print("HEY BOSS")
64 pass
65 if KeyboardInterrupt:
66 pass
67 >>>>>>> 2af4f5c (more sensory wall projects)