-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfrared_Control.ino
57 lines (48 loc) · 1.18 KB
/
Infrared_Control.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
void Infrared_Control(){
if(command == 'U'){
if (receiver.decode(&results)){
Serial.println(results.value);
delay(5);
receiver.resume();
}
/* if the incoming data is "defined hex code" then run the motors functions */
/* instead of zeros "0000", write the hex codes of your remote control */
if(results.value == 0000) MotorForward();
if(results.value == 0000) MotorBackward();
if(results.value == 0000) TurnRight();
if(results.value == 0000) TurnLeft();
if(results.value == 0000) MotorStop();
}
}
void MotorForward(){
motor1.setSpeed(130);
motor1.run(FORWARD);
motor2.setSpeed(130);
motor2.run(FORWARD);
}
void MotorBackward(){
motor1.setSpeed(130);
motor1.run(BACKWARD);
motor2.setSpeed(130);
motor2.run(BACKWARD);
}
void TurnRight(){
motor1.setSpeed(150);
motor1.run(FORWARD);
motor2.setSpeed(150);
motor2.run(BACKWARD);
delay(150);
}
void TurnLeft(){
motor1.setSpeed(150);
motor1.run(BACKWARD);
motor2.setSpeed(150);
motor2.run(FORWARD);
delay(150);
}
void MotorStop(){
motor1.setSpeed(0);
motor1.run(RELEASE);
motor2.setSpeed(0);
motor2.run(RELEASE);
}