-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_control_cardboard.ino
86 lines (72 loc) · 1.96 KB
/
remote_control_cardboard.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
/**
Remote Control Motor Driver
Set two motor pins based on input from an infrared remote control.
**/
#include <IRremote.h>
int remoteInputPin = 2;
IRrecv receiver(remoteInputPin);
decode_results results;
int motorRightForward = 9;
int motorRightReverse = 10;
int motorLeftForward = 11;
int motorLeftReverse = 12;
void setup() {
Serial.begin(9600);
receiver.enableIRIn();
pinMode(motorRightForward, OUTPUT);
pinMode(motorRightReverse, OUTPUT);
pinMode(motorLeftForward, OUTPUT);
pinMode(motorLeftReverse, OUTPUT);
}
void forward() {
digitalWrite(motorRightForward, HIGH);
digitalWrite(motorRightReverse, LOW);
digitalWrite(motorLeftForward, HIGH);
digitalWrite(motorLeftReverse, LOW);
}
void reverse() {
digitalWrite(motorRightForward, LOW);
digitalWrite(motorRightReverse, HIGH);
digitalWrite(motorLeftForward, LOW);
digitalWrite(motorLeftReverse, HIGH);
}
void left() {
digitalWrite(motorRightForward, HIGH);
digitalWrite(motorRightReverse, LOW);
digitalWrite(motorLeftForward, LOW);
digitalWrite(motorLeftReverse, HIGH);
}
void right() {
digitalWrite(motorRightForward, LOW);
digitalWrite(motorRightReverse, HIGH);
digitalWrite(motorLeftForward, HIGH);
digitalWrite(motorLeftReverse, LOW);
}
void halt() {
digitalWrite(motorRightForward, LOW);
digitalWrite(motorRightReverse, LOW);
digitalWrite(motorLeftForward, LOW);
digitalWrite(motorLeftReverse, LOW);
}
void loop() {
if (receiver.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value == 0xABCD) {
Serial.println("FORWARD");
forward();
} else if (results.value == 0xDCBA) {
Serial.println("REVERSE");
reverse();
} else if (results.value == 0x1234) {
Serial.println("LEFT");
left();
} else if (results.value == 0x4321) {
Serial.println("RIGHT");
right();
} else if (results.value == 0x0000) {
Serial.println("HALT");
halt();
}
receiver.resume();
}
}