-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir_car.ino
143 lines (126 loc) · 2.56 KB
/
ir_car.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Project: Infra-red arduino remote controlled car
* Autor: Pedro Igo Sousa Lucas
*/
#include <AFMotor.h>
//#include <Servo.h>
#include <IRremote.h>
AF_DCMotor motorL(1);
AF_DCMotor motorR(2);
//Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
const int irReceiverPin = A0;
IRrecv irrecv(irReceiverPin);
decode_results results;
int n, ser, vr, vl;
void setup() {
// myservo.attach(10);
n = 0;
//Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
//Serial.print("irCode: ");
//Serial.print(results.value, DEC);
switch (results.value){
case 16718055: //2
n = 2;
break;
case 16716015: //4
n = 4;
break;
case 16734885: //6
n = 6;
break;
case 16730805: //8
n = 8;
break;
case 16724175: //1
n = 1;
break;
case 16743045: //3
n = 3;
break;
case 16750695: //crazy
n = 9;
break;
default:
n = 0;
break;
}
// Serial.print(", bits: ");
// Serial.println(results.bits);
irrecv.resume();
}
switch (n){
case 0:
//ser = 1500;
vr = 0;
vl = vr;
runFor();
break;
case 2:
//ser = 1500;
vr = 200;
vl = vr;
runFor();
break;
case 4:
//ser = 1500;
vr = 200;
vl = 0;
runFor();
break;
case 6:
//ser = 1500;
vr = 0;
vl = 200;
runFor();
break;
case 8:
//ser = 1500;
vr = 200;
vl = vr;
runBack();
break;
case 1:
//ser = 1500;
vr = 200;
vl = 100;
runFor();
break;
case 3:
//ser = 1500;
vr = 100;
vl = 200;
runFor();
break;
case 9:
//ser = 1500;
vr = 200;
vl = 200;
runDevil();
break;
}
delay(200);
//myservo.writeMicroseconds(ser);
}
void runFor(){
motorL.setSpeed(vl);
motorL.run(BACKWARD);
motorR.setSpeed(vr);
motorR.run(BACKWARD);
}
void runBack(){
motorL.setSpeed(vl);
motorL.run(FORWARD);
motorR.setSpeed(vr);
motorR.run(FORWARD);
}
void runDevil(){
motorL.setSpeed(vl);
motorL.run(BACKWARD);
motorR.setSpeed(vr);
motorR.run(FORWARD);
}