*********
(7)Test Results:
After uploading the test code and powering it up, the servo rotates from 0
degree to 180 degrees.
Please note that we usually use library file to control servo.
(8)Code Explanation:
#include <Servo.h> is the Servo function and sentences that come with
Arduino. The following are several commonly used sentences of the
servo function:
1.Attach ( pin )--
set the pin of the servo
2.
write(angle)--it is
used to set the rotation angle of the steering gear.
The range of angle is 0° to 180°
3.read()--i
t is used to read the angle of the steering gear and can be
understood as reading the value in the last write() command
4.
attached()--
Determine whether the servo parameters have been sent to
the interface where the servo is connected
Note: The writing format of the above sentences is "Servo variable name.
Specific sentence ()" For example: myservo.attach(9).