1#include<IRremote.h>
2const int RemotePin=8;
3IRrecv irrecv(RemotePin);
4decode_results results;
5int in1=3;
6int in2=5;
7int in3=6;
8int in4=9;
9
10void setup() {
11 Serial.begin(9600);
12 irrecv.enableIRIn();
13 pinMode(in1, OUTPUT);
14 pinMode(in2, OUTPUT);
15 pinMode(in3, OUTPUT);
16 pinMode(in4, OUTPUT);
17
18}
19
20void loop() {
21
22 if(irrecv.decode(&results))
23 {
24 if (results.value==0xFF629D)
25 {
26 Forward();
27 }
28 else if (results.value==0xFFA857)
29 {
30 Backward();
31 }
32 else if (results.value==0xFF22DD)
33 {
34 Left();
35 }
36 else if (results.value==0xFFC23D)
37 {
38 Right();
39 }
40 else if (results.value==0xFF02FD)
41 {
42 Stop();
43 }
44 irrecv.resume();
45 }
46 }
47
48
49void Backward()
50 {
51 digitalWrite(in1,HIGH);
52 digitalWrite(in2,LOW);
53 digitalWrite(in3,HIGH);
54 digitalWrite(in4,LOW);
55 }
56 void Forward()
57 {
58 digitalWrite(in1,LOW);
59 digitalWrite(in2,HIGH);
60 digitalWrite(in3,LOW);
61 digitalWrite(in4,HIGH);
62 }
63 void Stop()
64 {
65 digitalWrite(in1,LOW);
66 digitalWrite(in2,LOW);
67 digitalWrite(in3,LOW);
68 digitalWrite(in4,LOW);
69 }
70 int Left()
71 {
72 digitalWrite(in1,LOW);
73 digitalWrite(in2,LOW);
74 digitalWrite(in3,LOW);
75 digitalWrite(in4,HIGH);
76 }
77 int Right()
78 {
79 digitalWrite(in1,LOW);
80 digitalWrite(in2,HIGH);
81 digitalWrite(in3,LOW);
82 digitalWrite(in4,LOW);
83 }