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