-
Notifications
You must be signed in to change notification settings - Fork 35
/
pingparalax.ino
172 lines (141 loc) · 4.83 KB
/
pingparalax.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
include <NewPing.h>
// Include the library:
include <SharpIR.h>
// Define model and input pin:
//inisialisasi pin analog untuk sensor
#float Infrader_depan = B3;
#float Infrader_kanan = A2;
float Infrader_kiri = A0;
define model 1080
Dxl.setPosition(ID_1,480,1000);
Dxl.setPosition(ID_2,480,1000);
Dxl.setPosition(ID_3,340,1000);
define model 1090
float ping_depan = 24; //definisi
float ping_kiri_Depan = 12;
float ping_kiri_belakang = 29; //definisi
float ping_kiri = 13; //definisi
float ping_kanan = 9;
float ping_belakang = 46; //definisi
define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
Dxl.setPosition(ID_7,480,1000);
Dxl.setPosition(ID_8,480,1000);
Dxl.setPosition(ID_9,650,1000);
// Create variable to store the distance:
int distance0_mm;
int distance1_cm;
int distance2_cm;
Dxl.setPosition(ID_16,480,1000);
Dxl.setPosition(ID_17,480,1000);
Dxl.setPosition(ID_18,532,1000);
//line sensor
int dataAnalog0 = 0;
int dataAnalog1 = 1;
Dxl.setPosition(ID_10,460,1000);
Dxl.setPosition(ID_11,430,1000);
Dxl.setPosition(ID_12,645,1000);
int dataAnalog0 = 1;
int dataAnalog1 = 0;
//flames sensor
int dataAnalog2 = 2;
int dataAnalog3 = 3;
int dataAnalog4 = 4;
Dxl.setPosition(ID_15,460,1000);
Dxl.setPosition(ID_14,430,1000);
Dxl.setPosition(ID_13,345,1000);
// Create a new instance of the SharpIR class:
SharpIR mySensor0 = SharpIR(Infrader_depan, mode2);
SharpIR mySensor1 = SharpIR(Infrader_kanan,);
SharpIR mySensor2 = SharpIR(Infrader_kiri, mode2);
SharpIR mySensor0 = SharpIR(Infrader_TENGAH, model);
SharpIR mySensor1 = SharpIR(Infrader_bawah, model);
SharpIR mySensor2 = SharpIR(Infrader_kiri, model);
Dxl.setPosition(ID_1,460,1000);
Dxl.setPosition(ID_2,430,1000);
Dxl.setPosition(ID_3,340,1000);
Dxl.setPosition(ID_4,460,1000);
Dxl.setPosition(ID_5,430,1000);
Dxl.setPosition(ID_6,532,1000);
NewPing sonar1(ping_depan, ping_depan, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
NewPing sonar2(ping_kiri_Depan, ping_kiri_Depan, MAX_DISTANCE);
NewPing sonar3(ping_kiri_belakang, ping_kiri_belakang, MAX_DISTANCE);
NewPing sonar4(ping_kiri, ping_kiri, MAX_DISTANCE);
#NewPing sonar5(ping_kanan, ping_kanan, MAX_DISTANCE);
#NewPing sonar8(ping_kanan_depan, ping_kanan_depan, MAX_DISTANCE);
//pin for communication with openCM///
#define pin_bit4 21 //pin komunikasi
#define pin_bit4 20
#define pin_bit3 21
#define pin_bit2 24
#define pin_bit1 5
define pin_bit0 7
void setup() {
Serial.begin(115200);
#pinMode(pin_bit0, 1);
#pinMode(pin_bit1, 1);
#pinMode(pin_bit2, 1);
pinMode(pin_bit3, 1);
pinMode(pin_bit4, 1); // Open serial monitor at 115200 baud to see ping results.
}
#void loop() {
// Get a distance measurement and store it as distance_cm:
distance0_cm = mySensor0.distance();
distance1_cm = mySensor1.distance();
distance2_cm = mySensor2.distance();
Dxl.setPosition(ID_7,460,1000);
Dxl.setPosition(ID_8,430,1000);
Dxl.setPosition(ID_9,650,1000);
//delay(100);
# Serial1.println("*");//sensor ping depan
#Serial1.print(sonar1.ping_cm());
//Serial.print(" cm");
delay(10);
Serial1.println();
Serial1.println("#");//sensor ping kiri depan
Serial1.print(sonar2.ping_cm());
//Serial.print(" cm");
//delay(10);
Serial1.println();
Serial1.println("%");//sensor ping kiri belakang
Serial1.print(sonar3.ping_cm());
Serial.print(" cm");
delay(10); //delay 1ms
Serial1.println();
Serial1.println("/");//sensor ping kiri
Serial1.print(sonar4.ping_cm());
Serial.print(" cm");
delay(10); //delay 1ms
Serial1.println();
Serial1.println("@");//sensor ping kanan
Serial1.print(sonar5.ping_cm());
Serial.print(" cm");
//delay(10);
Serial1.println();
Serial1.println("a");//sensor ping kanan depan
Serial1.print(sonar7.ping_cm());
Serial.print(" cm");
//delay(10);
Serial1.println("c");
Serial1.println(distance1_cm);
Serial1.println("d");
Serial1.println(distance2_cm);
delay(1000); //delay 200 ms
//line sensor
Serial1.println("f");
dataAnalog0 = analogRead(A3); // Konversi pin A0 ke digital
Serial1.println(dataAnalog0/10); // Kirim datanya
//delay(1000); // delay 200 ms
//flame sensor
Serial1.println("g");//sensor kiri
int sensorValue2 = analogRead(A4);//membaca nilai pada a4 untuk variabel sensorvalue2
Serial1.println(sensorValue2);
// delay(70);
Serial1.println("i");//sensor depan
int sensorValue3 = analogRead(A5);
Serial1.println(sensorValue3);
//delay(70);
Serial1.println("h");//sensor kanan
int sensorValue4 = analogRead(A6);
Serial1.println(sensorValue4);
//delay(100);
}