-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineFollowerArduino.ino
158 lines (118 loc) · 2.88 KB
/
lineFollowerArduino.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const int IN1 = 5;
const int IN2 = 4;
const int IN3 = 3;
const int IN4 = 2;
const int EN = 10; //const int lights = 13;
//const int horn = 8;
int pwm = 80;
char command = 'E';
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bits per second:
//Set pins as outputs
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(EN, OUTPUT);
//pinMode(lights, OUTPUT);
//pinMode(horn, OUTPUT);
//void stop();
//digitalWrite(lights, LOW);
// digitalWrite(horn, LOW);
}
void Stop()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
void Front()
{
//This function will turn Motors front.
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Back()
{
//This function will turn Motors backward.
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void Left()
{
analogWrite(EN, pwm+50);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(100);
}
void Right()
{
analogWrite(EN, pwm+50);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(100);
}
/*void Lights()
{
if (digitalRead(lights)==LOW)
digitalWrite(lights,HIGH);
else
digitalWrite(lights,LOW);
}
void Horn()
{
int i;
//for(i = 0; i < 4 ; i++)
{
digitalWrite(horn,HIGH);
delay(200);
digitalWrite(horn,LOW);
delay(200);
if(i=1)
delay(400);
}
}
/*
void turbo()
{
if (speed == 200)
speed = 255;
else
speed = 200;
}
*/
void loop() {
//delay(500);
//recieve bluetooth signal
if(Serial.available() > 0) // Send data only when you receive data:
{
command = Serial.read(); //Read the incoming data & store into data
// Serial.print(command);
}
analogWrite(EN, pwm);
//Serial.print("Switch");
switch (command) {
case 'f' : Front(); break;
case 'b' : Back(); break;
case 'l' : Left(); break;
case 'r' : Right(); break;
// case 'Q' : Lights(); break;
//case 'H' : Horn(); break;
case 'E' : Stop();break;
//case 'T' : turbo();break;
//case '.' : FullStop(); break;
}
delay(50);
Stop();
// delay(300);
command = ' ';
}