Main Content

servo

Connection to servo motor on Arduino MKR Motor Carrier or Nano Motor Carrier

Description

This object represents a connection to a servo motor with the specified motor number on an MKR Motor Carrier or a Nano Motor Carrier. You can control the servo motor using the functions listed under Object Functions.

Creation

Description

example

servoObj = servo(mcObj,motornumber) creates a connection to the servo motor at the specified motor number on the Arduino® MKR Motor Carrier or Nano Motor Carrier.

Input Arguments

expand all

Connection to the MKR Motor Carrier or Nano Motor Carrier, specified as an object.

Example: servoObj = servo(mcObj,1) creates a servo motor connection at motor number 1 connected to Servo1.

Servo motor number where the motor is connected on an MKR Motor Carrier or Nano Motor Carrier, specified as a number.

Properties

expand all

This property is read-only.

Servo motor number where the motor is connected on an MKR Motor Carrier or Nano Motor Carrier, specified as a number.

Example:

>> servoObj.MotorNumber
ans = 
      1 

Data Types: numeric

Object Functions

Use these object functions to create a connection to the servo motor.

writePositionWrite position of servo motor connected to MKR Motor Carrier or Nano Motor Carrier

Examples

collapse all

Create an arduino object with the 'MotorCarrier' library.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier')
arduinoObj = 
  arduino with properties:

                  Port: '/dev/ttyACM0'
                 Board: 'Nano33IoT'
         AvailablePins: {'D0-D13', 'A0-A7'}
  AvailableDigitalPins: {'D0-D13', 'A0-A7'}
      AvailablePWMPins: {'D2-D6', 'D9-D10'}
   AvailableAnalogPins: {'A0-A3', 'A6-A7'}
    AvailableI2CBusIDs: [0]
AvailableSerialPortIDs: [1]
             Libraries: {'MotorCarrier'}
Show all properties

Create a connection to the Nano Motor Carrier.

mcObj = motorCarrier(arduinoObj)
mcObj = 
  MotorCarrier with properties:

          SCLPin: 'A5'
          SDAPin: 'A4'
      I2CAddress: 102 ('0x66')

Create a servo motor connection.

servoObj = servo(mcObj,4)
servoObj = 
  Servo with properties:

    MotorNumber: 4 (Servo4)

Introduced in R2020a