long bacajarak (int triggerPin, int echoPin){
pinMode(triggerPin, OUTPUT);
pinMode(echoPin,INPUT);
digitalWrite(triggerPin, LOW);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
return pulseIn(echoPin,HIGH);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int cm = 0;
cm = (0.03446 * bacajarak(2,3))/2;
Serial.print(cm);
Serial.println("cm");
delay(100);
}