-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathline_follower.cpp
47 lines (44 loc) · 1.03 KB
/
line_follower.cpp
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
int leftInput=A3;
int rightInput=A4;
int leftMotor=13;
int rightMotor=12;
int leftValue = 0;
int rightValue = 0;
void setup()
{
pinMode (leftMotor, OUTPUT);
pinMode (rightMotor, OUTPUT);
}
void loop()
{
leftValue = analogRead (leftInput);
rightValue= analogRead (rightInput);
if(leftValue < 900 && rightValue < 900)
{
digitalWrite (leftMotor, HIGH);
digitalWrite (rightMotor, HIGH);
}
else
{
if(leftValue > 900 && rightValue < 900)
{
digitalWrite (leftMotor, LOW);
digitalWrite (rightMotor, HIGH);
}
else {
if (leftValue < 900 && rightValue > 900)
{
digitalWrite (rightMotor, LOW);
digitalWrite (leftMotor, HIGH);
}
else
{
if (leftValue > 900 && rightValue > 900)
{
digitalWrite (rightMotor, LOW);
digitalWrite (leftMotor, LOW);
}
}
}
}
}