-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoice_Follower.ino
84 lines (77 loc) · 1.52 KB
/
Voice_Follower.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
void Voice_Follower(){
if(command == 'R'){
while (Serial.available()){
delay(10);
char c = Serial.read();
if (c == '#') {break;}
voice += c;
}
if (voice.length() > 0){
if(voice == "*forward"){
forward_car();
}
else if(voice == "*backward"){
back_car();
}
else if(voice == "*turn right") {
right_car();
}
else if(voice == "*turn left") {
left_car();
}
else if(voice == "*stop car") {
stop_car();
}
voice="";
}
}
Read_Data();
}
void forward_car(){
motor1.run(FORWARD);
motor1.setSpeed(255);
motor2.run(FORWARD);
motor2.setSpeed(255);
delay(2000);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void back_car(){
motor1.run(BACKWARD);
motor1.setSpeed(255);
motor2.run(BACKWARD);
motor2.setSpeed(255);
delay(2000);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void right_car(){
myservo1.write(0);
delay(1000);
myservo1.write(120);
delay(1000);
motor1.run(FORWARD);
motor1.setSpeed(255);
motor2.run(BACKWARD);
motor2.setSpeed(255);
delay(1000);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void left_car(){
myservo1.write(180);
delay(1000);
myservo1.write(120);
delay(1000);
motor1.run(BACKWARD);
motor1.setSpeed(255);
motor2.run(FORWARD);
motor2.setSpeed(255);
delay(1000);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void stop_car(){
motor1.run(RELEASE);
motor2.run(RELEASE);
}