-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExcercise1
74 lines (67 loc) · 1.57 KB
/
Excercise1
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
from gpiozero import LED , DistanceSensor
from time import sleep
sensor = DistanceSensor(echo=18, trigger=17)
RLED = LED(16)
YLED = LED(14)
GLED = LED(15)
State = "Idle"
def get_distance():
cm = sensor.distance * 100
return cm
while True:
if State == "Idle":
RLED.off()
GLED.off()
YLED.off()
d=get_distance()
if d>5 and d<15:
State = "Close"
print("Close1")
if d>25 and d<30:
State = "Far"
print("Far1")
if d>15 and d<25:
State = "Near"
print("Near1")
elif State == "Close":
RLED.on()
GLED.on()
YLED.on()
d=get_distance()
if d>30:
State = "Idle"
print("Idle2")
if d>15 and d<25:
State = "Near"
print("Near2")
if d>25 and d<30:
State = "Far"
print("Far2")
elif State == "Near":
RLED.off()
GLED.on()
YLED.on()
d=get_distance()
if d>30:
State = "Idle"
print("Idle3")
if d>5 and d<15:
State = "Close"
print("Close3")
if d>15 and d<25:
State = "Far"
print("Far3")
elif State == "Far":
RLED.off()
GLED.off()
YLED.on()
d=get_distance()
if d>30:
State = "Idle"
print("Idle4")
if d>5 and d<15:
State = "Close"
print("Close4")
if d>15 and d<25:
State = "Near"
print("Near4")