EasyManua.ls Logo

Keyestudio Ks0428 - Page 96

Keyestudio Ks0428
247 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
96
www.keyestudio.com
servo
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to
0 degrees
procedure(pos); // tell servo to go to position in
variable 'pos'
delay(15);
}
}
// function to control servo
void procedure(int myangle) {
pulsewidth = myangle * 11 + 500; //calculate the value of pulse
width
digitalWrite(servoPin,HIGH);
delayMicroseconds(pulsewidth); //The duration of high level is
pulse width
digitalWrite(servoPin,LOW);
delay((20 - pulsewidth / 1000)); // the cycle is 20ms, the low
level last for the rest of time
}
//********************************************************************
********
Upload code successfully, servo swings back in the range of 0° to

Table of Contents