Page 29 - MDP2020-2
P. 29
················································································ 명장양성프로젝트 【MDP】 과제발표회 자료집 Ⅱ | 23
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
duration3 = pulseIn(echoPin3, HIGH);
distance3= duration3*0.034/2;
if (distance3 >= 500 || distance3 <= 0){
Serial.println("Out of range");
}
else {
Serial.print("Sensor3 : ");
Serial.print(distance3);
Serial.println("cm");
}
delay(2000);
digitalWrite(trigPin4, LOW);
delayMicroseconds(2);
digitalWrite(trigPin4, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin4, LOW);
duration4 = pulseIn(echoPin4, HIGH);
distance4= duration4*0.034/2;
if (distance4 >= 500 || distance4 <= 0){
Serial.println("Out of range");
}
else {
Serial.print("Sensor4 : ");
Serial.print(distance4);
Serial.println("cm");
Serial.println("");
}
delay(2000);
}