Main Content

readPosition

Read position from servo motor connected to Adafruit Motor Shield

Description

example

position = readPosition(s) reads the position of the motor shaft and returns the value of the position in ratio to the maximum angle of the specified servo motor.

Examples

collapse all

Connect to Arduino hardware, and create an add-on connection to an Adafruit Motor Shield.

a = arduino('COM4','Uno','Libraries','Adafruit/MotorShieldV2');
shield = addon(a,'Adafruit/MotorShieldV2');

Create a servo motor connection to motor number 1 on the shield.

s = servo(shield,1);

Read the position of the servo.

position = readPosition(s)
position = 0.5200

Input Arguments

collapse all

Servo motor connection, specified as a servo motor object.

Output Arguments

collapse all

Position of the servo motor, specified as a number representing the angle from 0 to 1.

Version History

Introduced in R2014b