-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrover.cpp
110 lines (110 loc) · 2.34 KB
/
rover.cpp
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
int motor1Pin1 = 5;
int motor1Pin2 = 6;
int motor2Pin1 = 8;
int motor2Pin2 = 7;
char dataIn = 'S';
char determinant;
char det;
int vel = 0;
int whitelight = 13;
int redlight = 10;
void setup() {
Serial.begin(9600);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(whitelight, OUTPUT);
pinMode(redlight, OUTPUT);
digitalWrite(whitelight, LOW);
digitalWrite(redlight, LOW);
}
void loop() {
det = check();
switch (det){
case 'F': // F, move forward
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
det = check();
break;
case 'B': // B, move back
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
det = check();
break;
case 'L':// L, move wheels left
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
det = check();
break;
case 'R': // R, move wheels right
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
det = check();
break;
case 'S': // S, stop
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
det = check();
break;
case 'U': // V, Red light on
//Serial.println("Red LIght On");
digitalWrite(redlight, HIGH);
break;
case 'u': //v, Red light off
//Serial.println("Red Light Off");
digitalWrite(redlight, LOW);
break;
case 'W': //W, Front Lights On
//Serial.println("White LIght On");
digitalWrite(whitelight, HIGH);
break;
case 'w': //w, Front Lights Off
//Serial.println("White Light Off");
digitalWrite(whitelight, LOW);
break;
}
}
int check(){
if (Serial.available() > 0){
dataIn = Serial.read();
if (dataIn == 'F'){//Forward
determinant = 'F';
}
else if (dataIn == 'B'){//Backward
determinant = 'B';
}
else if (dataIn == 'L'){//Left
determinant = 'L';
}
else if (dataIn == 'R'){//Right
determinant = 'R';
}
else if (dataIn == 'S'){//Stop
determinant = 'S';
}
else if (dataIn == 'U'){//Red Lights On
determinant = 'U';
}
else if (dataIn == 'u'){//Red Lights Off
determinant = 'u';
}
else if (dataIn == 'W'){//White Lights On
determinant = 'W';
}
else if (dataIn == 'w'){//White Lights Off
determinant = 'w';
}
return determinant;
}
}