Keyestudio Ks0428 Manual page 239

Table of Contents

Advertisement

www.keyestudio.com
flag = 1; //end loop
}}}}
//The function to control ultrasonic sensor the function controlling
ultrasonic sensor
float checkdistance() {
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
float distance = pulseIn(Echo, HIGH) / 58.00; //58.20 means
2*29.1=58.2
delay(10);
return distance;
}
//The function to control servo the function controlling servo
void procedure(int myangle) {
for (int i = 0; i <= 50; i = i + (1)) {
pulsewidth = myangle * 11 + 500;
digitalWrite(servoPin,HIGH);
delayMicroseconds(pulsewidth);
digitalWrite(servoPin,LOW);
delay((20 - pulsewidth / 1000));
239

Advertisement

Table of Contents
loading

Table of Contents