-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineFollowerRoboCar.ino
More file actions
70 lines (70 loc) · 1.14 KB
/
LineFollowerRoboCar.ino
File metadata and controls
70 lines (70 loc) · 1.14 KB
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
#define ls 2
#define rs 4
int pin1=3;
int pin2=5;
int pin3=6;
int pin4=9;
void setup()
{
Serial.begin(9600);
pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
pinMode(ls,INPUT);
pinMode(rs,INPUT);
}
void loop()
{
if(!digitalRead(ls)&&!digitalRead(rs))
{
forward();
}
else if(digitalRead(ls)&&!digitalRead(rs))
{
left();
}
else if(!digitalRead(ls)&&(digitalRead(rs)))
{
right();
}
else if((digitalRead(ls))&&(digitalRead(rs)))
{
finish();
}
}
void backward()
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
}
void forward()
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
}
void right()
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
digitalWrite(pin4,LOW);
}
void left()
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW);
digitalWrite(pin4,HIGH);
}
void finish()
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
}