-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot_Car_code.ino
83 lines (74 loc) · 1.79 KB
/
Robot_Car_code.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
int Left_p=11;
int Left_n=10;
int Right_p=13;
int Right_n=12;
int threshold=300;
int ultra_threshold=450;
int rightcorner=210;
//int Sensor=9;
void setup()
{
Serial.begin(9600);
pinMode (Left_p,OUTPUT);
pinMode (Left_n,OUTPUT);
pinMode (Right_p,OUTPUT);
pinMode (Right_n,OUTPUT);
//pinMode (Sensor;OUTPUT);
pinMode (A0,INPUT);
pinMode (A1,INPUT);
pinMode (A2,INPUT);
pinMode (A3,INPUT);
pinMode (A4,INPUT);
//pinMode (A5,INPUT);
}
void loop()
{
int ex_right=analogRead (A0);
int ex_left=analogRead (A1);
int ultra=analogRead (A2);
Serial.println(ultra);
if (ultra > ultra_threshold) {
digitalWrite (Left_p,LOW);
digitalWrite (Left_n,LOW);
digitalWrite (Right_p,LOW);
digitalWrite (Right_n,LOW);
Serial.println("STOP");
} else {
// straight
if (ex_left>threshold && ex_right>threshold)
{
digitalWrite (Left_p,HIGH);
digitalWrite (Left_n,LOW);
digitalWrite (Right_p,HIGH);
digitalWrite (Right_n,LOW);
Serial.println("straight");
}
// right
if(ex_left>threshold && ex_right<threshold)
{
digitalWrite (Left_p,HIGH);
digitalWrite (Left_n,LOW);
digitalWrite (Right_p,LOW);
digitalWrite (Right_n,LOW);
Serial.println("right");
}
// left
if(ex_left<threshold && ex_right>threshold)
{
digitalWrite (Left_p,LOW);
digitalWrite (Left_n,LOW);
digitalWrite (Right_p,HIGH);
digitalWrite (Right_n,LOW);
Serial.println("left");
}
// fuck
if(ex_left<threshold && ex_right<threshold)
{
digitalWrite (Left_p,LOW);
digitalWrite (Left_n,LOW);
digitalWrite (Right_p,HIGH);
digitalWrite (Right_n,LOW);
Serial.println("fuck");
}
}
}