-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths4_code.html
207 lines (111 loc) · 2.85 KB
/
s4_code.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html>
<head>
<title>voice code</title>
</head>
<body>
<pre style="font-size: 2em;color: #fff;background-color: #000;">
<code>
nt input1leftmotor=7;
int input2leftmotor=3;
int input3rightmotor=2;
int input4rightmotor=4;
void setup() {
pinMode(input1leftmotor, OUTPUT);
pinMode(input2leftmotor, OUTPUT);
pinMode(input3rightmotor, OUTPUT);
pinMode(input4rightmotor, OUTPUT); // put your setup code here, to run once:
}
void loop() {
digitalWrite(input1leftmotor,HIGH);
digitalWrite(input2leftmotor,LOW);
digitalWrite(input3rightmotor,HIGH);
digitalWrite(input4rightmotor,LOW); // put your main code here, to run repeatedly:
}
int ldr1center=A0;
int ldr2left=A1;
int ldr3right=A2;
void setup() {
pinMode(ldr1center, INPUT);
pinMode(ldr2left, INPUT);
pinMode(ldr3right, INPUT);
Serial.begin(9600); // put your setup code here, to run once:
}
void loop() {
int value1=analogRead(ldr1center);
int value2=analogRead(ldr2left);
int value3=analogRead(ldr3right);
Serial.print("value1=");
Serial.println(value1);
delay(2000);
Serial.print("value2=");
Serial.println(value2);
delay(2000);
Serial.print("value3=");
Serial.println(value3);
delay(2000); // put your main code here, to run repeatedly:
}
int enablepin1=11;
int enablepin2=12;
int input1leftmotor=2;
int input2leftmotor=4;
int input3rightmotor=7;
int input4rightmotor=3;
int ldr1center=A0;
int ldr2left=A1;
int ldr3right=A2;
void setup() {
pinMode(input1leftmotor, OUTPUT);
pinMode(input2leftmotor, OUTPUT);
pinMode(enablepin1, OUTPUT);
pinMode(input3rightmotor, OUTPUT);
pinMode(input4rightmotor, OUTPUT);
pinMode(enablepin2, OUTPUT);
pinMode(ldr1center, INPUT);
pinMode(ldr2left, INPUT);
pinMode(ldr3right, INPUT);
delay(2000);
Serial.begin(9600);
}
void loop() {
int value1=analogRead(ldr1center);
int value2=analogRead(ldr2left);
int value3=analogRead(ldr3right);
if (value1>value2&&value1>value3) {
straight();
delay(1000);
Serial.println("straight");
}
else if (value2>value1&&value2>value3) {
left();
Serial.println("left");
delay(600);
}
else if (value3>value1&&value3>value2) {
right();
delay(600);
Serial.println("right");
}
}
void straight(){
digitalWrite(input1leftmotor,HIGH);
digitalWrite(input2leftmotor,LOW);
digitalWrite(input3rightmotor,HIGH);
digitalWrite(input4rightmotor,LOW);
}
void left(){
digitalWrite(input1leftmotor,LOW);
digitalWrite(input2leftmotor,LOW);
digitalWrite(input3rightmotor,HIGH);
digitalWrite(input4rightmotor,LOW);
}
void right(){
digitalWrite(input1leftmotor,HIGH);
digitalWrite(input2leftmotor,LOW);
digitalWrite(input3rightmotor,LOW);
digitalWrite(input4rightmotor,LOW);
}
</code>
</pre>
</body>
</html>