Skip to content

Commit c5dfda8

Browse files
committed
add keyboard controlled car
1 parent b8e83fb commit c5dfda8

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Arduino/keyboard_controlled_car.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
int in2=8; //these correspond to the 4 terminals of a pair of motors
2+
int in1=7;
3+
int in3=5;
4+
int in4=4;
5+
char data;
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
pinMode(in1,OUTPUT);
10+
pinMode(in2,OUTPUT);
11+
pinMode(in3,OUTPUT);
12+
pinMode(in4,OUTPUT);
13+
}
14+
15+
void loop() {
16+
if (Serial.available()>0){
17+
data=Serial.read();
18+
//Serial.print(data);
19+
if (data=='G'){ //different letters here can correspond to different actions according to your connections
20+
digitalWrite(in1,LOW);
21+
digitalWrite(in2,HIGH);
22+
digitalWrite(in3,HIGH);
23+
digitalWrite(in4,LOW);
24+
}
25+
else if (data=='F'){
26+
digitalWrite(in1,HIGH);
27+
digitalWrite(in2,LOW);
28+
digitalWrite(in3,LOW);
29+
digitalWrite(in4,HIGH);
30+
}
31+
else if (data=='S'){
32+
digitalWrite(in1,LOW);
33+
digitalWrite(in2,LOW);
34+
digitalWrite(in3,LOW);
35+
digitalWrite(in4,LOW);
36+
}
37+
else if (data=='R'){
38+
digitalWrite(in1,HIGH);
39+
digitalWrite(in2,LOW);
40+
digitalWrite(in3,HIGH);
41+
digitalWrite(in4,LOW);
42+
}
43+
44+
else if (data=='L'){
45+
digitalWrite(in1,LOW);
46+
digitalWrite(in2,HIGH);
47+
digitalWrite(in3,LOW);
48+
digitalWrite(in4,HIGH);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)