1#include <SoftwareSerial.h>
2#include <Servo.h>
3Servo myservo;
4int pos = 0;
5
6SoftwareSerial bluetoothSerial(0, 1);
7char t;
8
9int lb =5;
10int lf = 6;
11int rf = 7;
12int rb = 8;
13
14void setup() {
15Serial.begin(9600);
16bluetoothSerial.begin(9600);
17pinMode(lf,OUTPUT);
18pinMode(lb,OUTPUT);
19pinMode(rf,OUTPUT);
20pinMode(rb,OUTPUT);
21myservo.attach(9);
22for (pos = 0; pos <= 180; pos += 1)
23myservo.write(0);
24delay(1000);
25myservo.write(180);
26delay(1000);
27myservo.write(90);
28delay(1000);
29
30
31
32}
33
34void loop() {
35
36if (bluetoothSerial.available()) {
37 t = bluetoothSerial.read();
38 Serial.print(t);
39 }
40
41 if (Serial.available()) {
42 t = Serial.read();
43 bluetoothSerial.print(t);
44 }
45
46if(t == 'W'){
47 digitalWrite(rf,HIGH);
48 digitalWrite(lf,HIGH);
49 digitalWrite(rb,LOW);
50 digitalWrite(lb,LOW);
51
52}
53
54else if(t == 'S'){
55 digitalWrite(rf,LOW);
56 digitalWrite(lf,LOW);
57 digitalWrite(rb,HIGH);
58 digitalWrite(lb,HIGH);
59}
60
61else if(t == 'A'){
62 digitalWrite(rb,LOW);
63 digitalWrite(lf,LOW);
64 digitalWrite(rf,HIGH);
65 digitalWrite(lb,HIGH);
66}
67
68else if(t == 'D'){
69 digitalWrite(rf,LOW);
70 digitalWrite(lb,LOW);
71 digitalWrite(lf,HIGH);
72 digitalWrite(rb,HIGH);
73}
74
75else if(t == 'X'){
76 digitalWrite(rf,LOW);
77 digitalWrite(rb,LOW);
78 digitalWrite(lf,LOW);
79 digitalWrite(lb,LOW);
80}
81
82else if(t == 'Q'){
83 digitalWrite(rf,HIGH);
84}
85
86else if(t == 'E'){
87 digitalWrite(lf,HIGH);
88}
89
90else if(t == 'Z'){
91 digitalWrite(rb,HIGH);
92}
93
94else if(t == 'C'){
95 digitalWrite(lb,HIGH);
96}
97
98else if(t == 'R'){
99 myservo.write(90);
100 digitalWrite(rf,LOW);
101 digitalWrite(rb,LOW);
102 digitalWrite(lf,LOW);
103 digitalWrite(lb,LOW);
104 delay(500);
105 digitalWrite(rf,HIGH);
106 digitalWrite(lf,HIGH);
107 delay(100);
108 myservo.write(80);
109 delay(100);
110 myservo.write(70);
111 delay(100);
112 myservo.write(60);
113 delay(100);
114 myservo.write(50);
115 delay(100);
116 myservo.write(40);
117 delay(100);
118 myservo.write(30);
119 delay(100);
120 digitalWrite(rf,LOW);
121 myservo.write(90);
122 delay(1000);
123 digitalWrite(rf,LOW);
124 digitalWrite(rb,LOW);
125 digitalWrite(lf,LOW);
126 digitalWrite(lb,LOW);
127}
128
129else if(t == 'F'){
130 myservo.write(90);
131 digitalWrite(rf,LOW);
132 digitalWrite(rb,LOW);
133 digitalWrite(lf,LOW);
134 digitalWrite(lb,LOW);
135 delay(500);
136 digitalWrite(rb,HIGH);
137 digitalWrite(lb,HIGH);
138 delay(100);
139 myservo.write(100);
140 delay(100);
141 myservo.write(110);
142 delay(100);
143 myservo.write(120);
144 delay(100);
145 myservo.write(130);
146 delay(100);
147 myservo.write(140);
148 delay(100);
149 myservo.write(150);
150 delay(100);
151 digitalWrite(rb,LOW);
152 myservo.write(90);
153 delay(1000);
154 digitalWrite(rf,LOW);
155 digitalWrite(rb,LOW);
156 digitalWrite(lf,LOW);
157 digitalWrite(lb,LOW);
158}
159else if(t == 'V'){
160 myservo.write(90);
161 digitalWrite(rf,LOW);
162 digitalWrite(rb,LOW);
163 digitalWrite(lf,LOW);
164 digitalWrite(lb,LOW);
165 delay(500);
166 digitalWrite(rf,HIGH);
167 digitalWrite(lb,HIGH);
168 delay(100);
169 myservo.write(80);
170 delay(100);
171 myservo.write(70);
172 delay(100);
173 myservo.write(60);
174 delay(100);
175 myservo.write(50);
176 delay(100);
177 myservo.write(40);
178 delay(100);
179 myservo.write(30);
180 delay(100);
181 digitalWrite(rf,LOW);
182 myservo.write(90);
183 delay(1000);
184 digitalWrite(rf,LOW);
185 digitalWrite(rb,LOW);
186 digitalWrite(lf,LOW);
187 digitalWrite(lb,LOW);
188}
189
190else if(t == 'j'){
191 myservo.write(20);
192}
193
194else if(t == 'h'){
195 myservo.write(29);
196}
197
198else if(t == 'g'){
199 myservo.write(37);
200}
201
202else if(t == 'f'){
203 myservo.write(46);
204}
205
206else if(t == 'd'){
207 myservo.write(55);
208}
209
210else if(t == 's'){
211 myservo.write(64);
212}
213
214else if(t == 'a'){
215 myservo.write(73);
216}
217
218else if(t == 'p'){
219 myservo.write(81);
220}
221
222else if(t == 'o'){
223 myservo.write(90);
224}
225
226else if(t == 'i'){
227 myservo.write(99);
228}
229
230else if(t == 'u'){
231 myservo.write(108);
232}
233
234else if(t == 'y'){
235 myservo.write(117);
236}
237
238else if(t == 't'){
239 myservo.write(125);
240}
241
242else if(t == 'r'){
243 myservo.write(138);
244}
245
246else if(t == 'e'){
247 myservo.write(143);
248}
249
250else if(t == 'w'){
251 myservo.write(152);
252}
253
254else if(t == 'q'){
255 myservo.write(160);
256}
257
258}