-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroladordp.ino
65 lines (57 loc) · 1.48 KB
/
controladordp.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
#include <Servo.h>
byte C1 = 3;
byte C2 = 5;
int V1;
int V2;
Servo TR;
Servo TL;
void setup() {
pinMode(C1, INPUT);
pinMode(C2, INPUT);
TR.attach(9);
TL.attach(10);
TR.writeMicroseconds(1500);
TL.writeMicroseconds(1500);
delay(1000);
Serial.begin(9600);
}
void ReadValues () {
V1 = pulseIn(C1, HIGH);
V2 = pulseIn(C2, HIGH);
Serial.println(V1);
Serial.println(V2);
}
void Move (){
int x;
int y;
if ((V1 > 1475 & V1 < 1515) & (V2 > 1475 & V2 < 1515)){
TR.writeMicroseconds(1500);
TL.writeMicroseconds(1500);
}
else if ((V1 > 1475 & V1 < 1515) & (V2 < 1475 || V2 > 1515)) {
TR.writeMicroseconds(map(V2, 988, 2012, 1100, 1900));
TL.writeMicroseconds(map(V2, 988, 2012, 1100, 1900));
}
else if ((V1 < 1475) & (V2 > 1475 & V2 < 1515)) {
TR.writeMicroseconds(map(V1, 988, 2012, 1100, 1900));
TL.writeMicroseconds(1500);
}
else if ((V1 > 1515) & (V2 > 1475 & V2 < 1515)) {
TL.writeMicroseconds(map(V1, 988, 2012, 1100, 1900));
TR.writeMicroseconds(1500);
}
else if ((V1 < 1475) & (V2 < 1475 || V2 > 1515)) {
y = V2 - (V2 - 1500)*((1500-V1)/512);
TR.writeMicroseconds(map(V2, 988, 2012, 1100, 1900));
TL.writeMicroseconds(map(y, 988, 2012, 1100, 1900));
}
else if ((V1 > 1515) & (V2 < 1475 || V2 > 1515)) {
y = V2 - (V2 - 1500)*((V1 - 1500)/512);
TL.writeMicroseconds(map(V2, 988, 2012, 1100, 1900));
TR.writeMicroseconds(map(y, 988, 2012, 1100, 1900));
}
}
void loop() {
ReadValues();
Move();
}