}
}
void SensorSetup(){
pinMode(URTRIG,OUTPUT); // A low pull on pin COMP/TRIG
digitalWrite(URTRIG,HIGH); // Set to HIGH
pinMode(URPWM, INPUT); // Sending Enable PWM mode comm
and
for(int i=0;i<4;i++){
Serial.write(EnPwmCmd[i]);
}
}
int MeasureDistance(){ // a low pull on pin COMP/TRIG triggering a se
nsor reading
digitalWrite(URTRIG, LOW);
digitalWrite(URTRIG, HIGH); // reading Pin PWM will output
pulses
unsigned long distance=pulseIn(URPWM,LOW);
if(distance==50000){ // the reading is invalid.
Serial.print("Invalid");
}else{
distance=distance/50; // every 50us low level stands for 1cm
}
return distance;
}
void servoSweep(){
if(sweepFlag ){
if(pos>=60 && pos<=120){
pos=pos+1; // in steps of 1 degree
myservo.write(pos); // tell servo to go to po
sition in variable 'pos'
}