setPosition()

Description

Sets the target angle of the servo.

Syntax

servo.setPosition(position)

servo.setPosition(position, time)

Parameters

servo: A variable of type AIServo.

position: A floating-point number representing the target angle. For example, 90.0 indicates the target position in degrees, meaning the servo will be at 90 degrees.

time (optional): The time it takes to reach the target angle. If no value is entered or the value is 0, the servo will rotate at its fastest speed.

Postback

None

Example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

#include <AIServo86.h>

  

AIServoPort(ROBOTIS, AX12) bus;

AIServo myservo;

  

void setup()

{

  bus.begin(Serial1, 1000000);

  myservo.attach(bus, 9);

  myservo.setPosition(150); // Set to rotate to 150 degrees at the fastest speed

  myservo.run(); // Rotate the servo

  myservo.setPosition(100, 1000); // Set to rotate to 100 degrees in 1 second

  myservo.run(); //Rotation servo

}

  

void loop() {}

See also

attach()


Library Reference Home

Text in the 86Duino reference material is adapted from the Arduino reference material and is licensed under the Creative Commons Attribution-Share Alike 3.0 License. The code examples in the reference materials have been released into the public domain.