void PWM_Mode_Setup(){
pinMode(URTRIG,OUTPUT); // A low pull on pin COM
P/TRIG
digitalWrite(URTRIG,HIGH); // Set to HIGH
pinMode(URPWM, INPUT); // Sending Enable PWM mo
de command
for(int i=0;i<4;i++){
Serial.write(EnPwmCmd[i]);
}
}
void PWM_Mode(){ // a low pull on pin COM
P/TRIG triggering a sensor reading
digitalWrite(URTRIG, LOW);
digitalWrite(URTRIG, HIGH); // reading Pin PWM will
output pulses
unsigned long DistanceMeasured=pulseIn(URPWM,LOW);
if(DistanceMeasured==50000){ // the reading is invali
d.
Serial.print("Invalid");
}
else{
Distance=DistanceMeasured/50; // every 50us low level
stands for 1cm
}
Serial.print("Distance=");
Serial.print(Distance);
Serial.println("cm");
}