-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLineFollower.ino
120 lines (99 loc) · 2.09 KB
/
LineFollower.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
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
#include <Servo.h>
#define WHEEL_SPEED 180
#define LEFT_WHEEL_PIN 6
#define RIGHT_WHEEL_PIN 7
//Line Follower
#define s0 A0
#define s1 A1
#define s2 A2
#define s3 A3
#define s4 A4
#define s5 2
#define s6 3
#define s7 4
int state;
int input;
String string;
bool boolState;
Servo wheelLeft;
Servo wheelRight;
void setup()
{
//Line Follower
pinMode(s0, INPUT);
pinMode(s1, INPUT);
pinMode(s2, INPUT);
pinMode(s3, INPUT);
pinMode(s4, INPUT);
pinMode(s5, INPUT);
pinMode(s6, INPUT);
pinMode(s7, INPUT);
Serial.begin(9600);
}
void loop()
{
//Line Follower Forward
Serial.println("Line Follower Forward");
while(true)
{
if(digitalRead(s4)== LOW && digitalRead(s5) == LOW && digitalRead(s6) == LOW && digitalRead(s7) == LOW && digitalRead(s3)== LOW && digitalRead(s2) == LOW && digitalRead(s1) == LOW && digitalRead(s0) == LOW )
moveStop();
else if(digitalRead(s3)== LOW && digitalRead(s4) == LOW)
moveForward();
else if(digitalRead(s3)== LOW || digitalRead(s2) == LOW || digitalRead(s1) == LOW || digitalRead(s0) == LOW)
moveRight();
else if(digitalRead(s4)== LOW || digitalRead(s5) == LOW || digitalRead(s6) == LOW || digitalRead(s7) == LOW)
moveLeft();
else
{
moveStop();
// break;
}
}
}
void moveForward()
{
attachWheel();
wheelLeft.write(WHEEL_SPEED);
wheelRight.write(-WHEEL_SPEED);
}
void moveReverse()
{
attachWheel();
wheelLeft.write(-WHEEL_SPEED);
wheelRight.write(WHEEL_SPEED);
}
void moveStop()
{
wheelLeft.detach();
wheelRight.detach();
}
void moveRight()
{
attachWheel();
wheelLeft.write(WHEEL_SPEED);
wheelRight.write(WHEEL_SPEED);
}
void moveLeft()
{
attachWheel();
wheelLeft.write(-WHEEL_SPEED);
wheelRight.write(-WHEEL_SPEED);
}
void moveRightReverse()
{
attachWheel();
wheelLeft.write(-WHEEL_SPEED);
wheelRight.write(-WHEEL_SPEED);
}
void moveLeftReverse()
{
attachWheel();
wheelLeft.write(WHEEL_SPEED);
wheelRight.write(WHEEL_SPEED);
}
void attachWheel()
{
wheelLeft.attach(LEFT_WHEEL_PIN);
wheelRight.attach(RIGHT_WHEEL_PIN);
}