-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal_code_for_Swarm_Slave_robo.ino
92 lines (79 loc) · 1.76 KB
/
Final_code_for_Swarm_Slave_robo.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
#define B1 4
#define B2 5
#define B3 6
#define B4 7
void setup() {
Serial.begin(9600);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(B1,INPUT);
pinMode(B2,INPUT);
pinMode(B3,INPUT);
pinMode(B4,INPUT);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
}
void moveRobot(String motion)
{
if(motion == "Backward")
{
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
Serial.println("Forward");
}
if(motion == "Forward")
{
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
Serial.println("Backward");
}
if(motion == "Right")
{
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
Serial.println("Left");
}
if(motion == "Left")
{
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
Serial.println("Right");
}
if(motion == "Stop")
{
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
Serial.println("Stop");
}
}
void loop() {
int D1= digitalRead(B1);
int D2= digitalRead(B2);
int D3= digitalRead(B3);
int D4= digitalRead(B4);
Serial.println(String(D1)+String(D2)+String(D3)+String(D4));
if((D1 == 0) && (D2 == 1) && (D3 == 0) && (D4 == 1)){
moveRobot("Forward");
}
if((D1 == 0) && (D2 == 0) && (D3 == 0) && (D4 == 0)){
moveRobot("Stop");
}
if((D1 ==0) && (D2 == 1) && (D3 == 1) && (D4 == 0)){
moveRobot("Right");
}
if((D1 == 1) && (D2 == 0) && (D3 == 0) && (D4 == 1)){
moveRobot("Left");
}
}