-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bluetooth_Car.ino
127 lines (103 loc) · 1.94 KB
/
Bluetooth_Car.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
int M1A = 2;//Right
int M1B = 3;
int M2A = 4;//left
int M2B = 5;
int x;
void setup() {
Serial.begin(9600); // initiates the serial port for communication with Bluetooth
pinMode(M1A, OUTPUT);
pinMode(M1B, OUTPUT);
pinMode(M2A, OUTPUT);
pinMode(M2B, OUTPUT);
digitalWrite(M1A,LOW);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
void loop() {
if(Serial.available()>0){ // read bluetooth and store in state
x = Serial.read();
}
Serial.println(x);
if(x == 83){
Stop();
}
if(x == 70 ){
Forward();
}
if(x == 66 ){
Backward();
}
if(x == 82 ){
Right_Sharp();
}
if(x == 76 ){
Left_Sharp();
}
if(x == 73 ){
F_Right();
}
if(x == 71 ){
F_Left();
}
if(x == 74 ){
B_Right();
}
if(x == 72 ){
B_Left();
}
}
void Forward(){
digitalWrite(M1A,HIGH);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,HIGH);
}
void Backward(){
digitalWrite(M1A,LOW);
digitalWrite(M1B,HIGH);
digitalWrite(M2A,HIGH);
digitalWrite(M2B,LOW);
}
void Right_Sharp(){
digitalWrite(M1A,LOW);
digitalWrite(M1B,HIGH);
digitalWrite(M2A,LOW);
digitalWrite(M2B,HIGH);
}
void Left_Sharp(){
digitalWrite(M1A,HIGH);
digitalWrite(M1B,LOW);
digitalWrite(M2A,HIGH);
digitalWrite(M2B,LOW);
}
void F_Right(){
digitalWrite(M1A,LOW); //RIGHT
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW); //LEFT
digitalWrite(M2B,HIGH);
}
void F_Left(){
digitalWrite(M1A,HIGH);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
void B_Right(){
digitalWrite(M1A,LOW);
digitalWrite(M1B,LOW);
digitalWrite(M2A,HIGH);
digitalWrite(M2B,LOW);
}
void B_Left(){
digitalWrite(M1A,LOW);
digitalWrite(M1B,HIGH);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
void Stop(){
digitalWrite(M1A,LOW);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}