-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
113 lines (94 loc) · 1.86 KB
/
main.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import time
import machine
ldr1 = machine.Pin(4, machine.Pin.OUT)
ldr2 = machine.Pin(5, machine.Pin.OUT)
ldr1val = 0
ldr2val = 0
retning = 40
adc = machine.ADC(0)
ldr1.value(0)
ldr2.value(0)
mp1 = machine.Pin(12, machine.Pin.OUT)
mp2 = machine.Pin(13, machine.Pin.OUT)
mp3 = machine.Pin(15, machine.Pin.OUT)
mp4 = machine.Pin(3, machine.Pin.OUT)
mp1.value(0)
mp2.value(0)
mp3.value(0)
mp4.value(0)
def turnl():
mp4.value(0)
mp1.value(1)
time.sleep_ms(25)
mp1.value(1)
mp2.value(1)
time.sleep_ms(25)
mp1.value(0)
mp2.value(1)
time.sleep_ms(25)
mp2.value(1)
mp3.value(1)
time.sleep_ms(25)
mp2.value(0)
mp3.value(1)
time.sleep_ms(25)
mp3.value(1)
mp4.value(1)
time.sleep_ms(25)
mp3.value(0)
mp4.value(1)
time.sleep_ms(25)
mp4.value(1)
mp1.value(1)
time.sleep_ms(25)
def turnr():
mp1.value(0)
mp4.value(1)
time.sleep_ms(25)
mp4.value(1)
mp3.value(1)
time.sleep_ms(25)
mp4.value(0)
mp3.value(1)
time.sleep_ms(25)
mp3.value(1)
mp2.value(1)
time.sleep_ms(25)
mp3.value(0)
mp2.value(1)
time.sleep_ms(25)
mp2.value(1)
mp1.value(1)
time.sleep_ms(25)
mp2.value(0)
mp1.value(1)
time.sleep_ms(25)
mp1.value(1)
mp4.value(1)
time.sleep_ms(25)
#print(ldr1val, ldr2val)
while True:
ldr1.value(1)
ldr1val = adc.read()
#print(ldr1val)
ldr1.value(0)
time.sleep_ms(100)
ldr2.value(1)
ldr2val = adc.read()
#print(ldr2val)
ldr2.value(0)
time.sleep_ms(100)
sammen = (ldr1val - ldr2val)
#print(sammen)
if (sammen >= 99):
for i in range(20):
turnr()
elif (sammen <= -99):
for i in range(20):
turnl()
else:
pass
mp1.value(0)
mp4.value(0)
#print("-------------------------")
time.sleep_ms(100)