-
Notifications
You must be signed in to change notification settings - Fork 0
/
remoteControl.cpp
53 lines (47 loc) · 945 Bytes
/
remoteControl.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
#include "carMain.h"
#include "remoteHexValues.h"
int direction;
/*Functions only used in remote-control of the car*/
void increase_speed(){
if (MotorSpeed<255){
MotorSpeed=MotorSpeed+20;
}
direction_check();
}
void decrease_speed(){
if (MotorSpeed>55){
MotorSpeed=MotorSpeed-20;
}
direction_check(); //applies the new speed, and resumes the current direction of motion.
}
void reset_speed(){
MotorSpeed=75;
}
void backup(){
reverse();
delay(1000);
if (random(1,10)<=5){
rotate90left();
}
else{
rotate90right();
}
}
/*functions used as a sub-function of the above, but not required elsewhere*/
void direction_check(){ //direction_check only occurs as a subfunction of increase_ and decrease_speed
if(direction==0){
forward();
}
if(direction==1){
reverse();
}
if(direction==2){
stop();
}
if(direction==3){
turn_left();
}
if(direction==4){
turn_right();
}
}