delay(20 - pulsewidth / 1000);
}
}
//***********************************************************************
***********
After uploading the test code, the servo rotate at 0°,90° and 180°
alternatively.
There is an easier way to control the servo that is use the servo library file
of Arduino. The following link is for your reference:
https://www.arduino.cc/en/Reference/Servo
(6) Test Code2:
Library file is used but the connection diagram remains the same.
/*
keyestudio sun_follower
lesson 9.2
servo
http://www.keyestudio.com
*/
#include <Servo.h> //include the library code:
Servo myservo;