-
Notifications
You must be signed in to change notification settings - Fork 1
/
Arduino_code.ino
74 lines (72 loc) · 1.61 KB
/
Arduino_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
int led = 3; //led
int outPin1 = 12; //motor1
int outPin2 = 11; //motor1
int outPin4 = 10; //motor2
int outPin3 = 9; //motor2
char bt = 0; //BT
void setup()
{
Serial.begin(9600);
pinMode(outPin1,OUTPUT);
pinMode(outPin2,OUTPUT);
pinMode(outPin3,OUTPUT);
pinMode(outPin4,OUTPUT);
pinMode(led,OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{
bt = Serial.read();
digitalWrite(led, 1);
if(bt == 'B') //move back
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,HIGH);
digitalWrite(outPin3,HIGH);
digitalWrite(outPin4,LOW);
}
else if (bt == 'F') //move forward
{
digitalWrite(outPin1,HIGH);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,HIGH);
}
else if (bt == 'S') //stop!!
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,LOW);
}
else if (bt == 'L') // move left
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,HIGH);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,HIGH);
}
else if (bt == 'R') //move right
{
digitalWrite(outPin1,HIGH);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,HIGH);
digitalWrite(outPin4,LOW);
}
else if (bt == 'G') //forward right
{
digitalWrite(outPin1,HIGH);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,HIGH);
}
else if (bt == 'I') //forward left
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,HIGH);
digitalWrite(outPin3,HIGH);
digitalWrite(outPin4,LOW);
}
}
}