-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathline.ino
61 lines (53 loc) · 1.11 KB
/
line.ino
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
#define lmotorf 9
#define lmotorb 6
#define rmotorf 5
#define rmotorb 3
void setup() {
pinMode(lmotorf,OUTPUT);
pinMode(rmotorf,OUTPUT);
pinMode(lmotorb,OUTPUT);
pinMode(rmotorb,OUTPUT);
pinMode(13,INPUT);
pinMode(7,INPUT);
pinMode(10,INPUT);
pinMode(8,INPUT);
}
void loop() {
int l1sensor=digitalRead(13);
int l2sensor=digitalRead(7);
int r1sensor=digitalRead(10);
int r2sensor=digitalRead(8);
int r1sensor=22;
int r2sensor=12;
if((l1sensor==HIGH)&&(r1sensor==HIGH)&&(l2sensor==HIGH)&&(r2sensor==HIGH))
{
// go forward
analogWrite(lmotorf,255);
analogWrite(rmotorf,255);
analogWrite(lmotorb,0);
analogWrite(rmotorb,0);
}
else if(((l1sensor==LOW)||(l2sensor==LOW))&&((r1sensor==HIGH)||(r2sensor==HIGH)))
{
// turn right
analogWrite(lmotorf,255);
analogWrite(rmotorf,0);
analogWrite(lmotorb,0);
analogWrite(rmotorb,255);
}
else if(((l1sensor==HIGH)||(l2sensor==HIGH))&& ((r1sensor==LOW)||(r2sensor==LOW)))
{
// turn left
analogWrite(lmotorf,0);
analogWrite(rmotorf,255);
analogWrite(lmotorb,255);
analogWrite(rmotorb,0);
}
else
{
analogWrite(lmotorf,0);
analogWrite(rmotorf,0);
analogWrite(lmotorb,0);
analogWrite(rmotorb,0);
}
}