[Servo86]
Description
Set the target position of the servo when run() is called.
Syntax
servo.setPosition(position)
servo.setPosition(position, time)
Parameters
servo
: The variable of Servo type.Position
: The target position of the servo. You can input integer and floating point values. When inputting an integer, the unit of the target position is us. For example, inputting 1500 represents the position of the servo corresponding to the PWM pulse of 1500us. When the input is a symbolic number, the unit of the target position is “degree”, for example, enter 90.0 to represent the 90 degree position of the servo.Time
(optional): Specify the desired time for the servo to rotate from the current position to the target position. If the input value is 0, the servo will rotate at the fastest speed; if there is no input value, the servo will rotate according to the speed set by setVelocity().
Returns
None.
Example
#include <Servo86.h> Servo myservo; void setup() { myservo.attach(9); myservo.setPosition(1500); // set the rotation to 1500us angle myservo.run(); // turn the servo delay(500); // delay 0.5 seconds myservo.setPosition(1900, 1000); // set the rotation to 1900us angle, it takes 1 second myservo.run(); // turn the servo } void loop() {}
See also
Libraries Reference Home
The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.