forked from VAR-solutions/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardcodedlinefollowerlsa.ino
More file actions
117 lines (96 loc) · 1.71 KB
/
hardcodedlinefollowerlsa.ino
File metadata and controls
117 lines (96 loc) · 1.71 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
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
#define dir2 7
#define pwm2 6
#define pwm1 5
#define dir1 4
#define pwm 9
#define dir 8
#define RX 1
#define TX 0
#define serialEn 2
#define jnPulse 3
#define An A0
int readVal,positionVal;
void forward()
{
analogWrite(pwm1,30);
digitalWrite(dir1,LOW);
analogWrite(pwm2,30);
digitalWrite(dir2,LOW);
analogWrite(pwm,LOW);
digitalWrite(dir,LOW);
}
void right()
{
analogWrite(pwm1,30);
digitalWrite(dir1,LOW);
analogWrite(pwm2,30);
digitalWrite(dir2,HIGH);
analogWrite(pwm,30);
digitalWrite(dir,HIGH);
}
void left()
{
analogWrite(pwm1,30);
digitalWrite(dir1,HIGH);
analogWrite(pwm2,30);
digitalWrite(dir2,LOW);
analogWrite(pwm,30);
digitalWrite(dir,LOW);
}
void reverse()
{
analogWrite(pwm1,30);
digitalWrite(dir1,HIGH);
analogWrite(pwm2,30);
digitalWrite(dir2,HIGH);
analogWrite(pwm,LOW);
digitalWrite(dir,LOW);
}
void stopbot()
{
analogWrite(pwm1,LOW);
analogWrite(pwm2,LOW);
analogWrite(pwm,LOW);
}
void setup() {
Serial.begin(9600);
pinMode(dir2,OUTPUT);
pinMode(dir1,OUTPUT);
pinMode(pwm1,OUTPUT);
pinMode(pwm2,OUTPUT);
pinMode(dir,OUTPUT);
pinMode(pwm,OUTPUT);
pinMode(serialEn,OUTPUT);
pinMode(jnPulse,INPUT);
digitalWrite(serialEn,30);
analogWrite(pwm1,LOW);
digitalWrite(dir1,LOW);
analogWrite(pwm2,LOW);
digitalWrite(dir2,LOW);
analogWrite(pwm,LOW);
digitalWrite(dir,LOW);
delay(3000);
}
void loop() {
readVal = analogRead(An);
positionVal = ((float)readVal/921)*70;
if(positionVal<=25)
{
left();
delay(30);
}
else if(positionVal<=40)
{
forward();
}
else if(positionVal<=70)
{
right();
delay(30);
}
else
{
right();
delay(30);
}
}