Motor
[Libraries]

The Motor subsystem provides forward/reverse and speed control for up to 4 DC motors across the 8 high current outputs. More...


Functions

int Motor_SetActive (int index, int state)
 Sets whether the specified motor is active.
int Motor_GetActive (int index)
 Returns the active state of the DC Motor I/O lines.
int Motor_SetSpeed (int index, int duty)
 Set the speed of a DC motor.
int Motor_SetDirection (int index, char forward)
 Set the direction of a DC motor.
int Motor_GetSpeed (int index)
 Read the speed of a DC motor.
int Motor_GetDirection (int index)
 Read the direction of a DC motor.

Detailed Description

The Motor subsystem provides forward/reverse and speed control for up to 4 DC motors across the 8 high current outputs.

Each motor controller is composed of 2 adjacent Digital Outs on the Make Application Board:

Other output devices cannot be used simultaneously - for example, the DigitalOuts cannot be called without first setting overlapping the DC motor I/O lines to inactive.

See the digital out section of the Application Board overview for more details.


Function Documentation

int Motor_GetActive ( int  index  ) 

Returns the active state of the DC Motor I/O lines.

Parameters:
index An integer specifying which DC Motor (0-3).
Returns:
The availability of the motor's I/O lines - 1 (active) or 0 (inactive).
Example
  if( Motor_GetActive(0) )
  {
    // Motor 0 is active
  }
  else
  {
    // Motor 0 is inactive
  }

Definition at line 101 of file motor.c.

int Motor_GetDirection ( int  index  ) 

Read the direction of a DC motor.

Parameters:
index An integer specifying which DC Motor (0-3).
Returns:
Direction - non-zero (forward) or 0 (reverse).
Example
  if( Motor_GetDirection(0) )
  {
    // Motor 0 is going forward
  }
  else
  {
    // Motor 0 is going in reverse
  }

Definition at line 215 of file motor.c.

int Motor_GetSpeed ( int  index  ) 

Read the speed of a DC motor.

Parameters:
index An integer specifying which DC Motor (0-3).
Returns:
the speed (0 - 1023)
Example
  // check the current speed of motor 1
  int motor1_speed = Motor_GetSpeed(1);

Definition at line 181 of file motor.c.

int Motor_SetActive ( int  index,
int  state 
)

Sets whether the specified motor is active.

Parameters:
index An integer specifying which Motor (0-3).
state An integer specifying the availability of the motor's I/O lines - 1 (active) or 0 (inactive).
Returns:
Zero on success.
Example
  // Enable motor 0
  Motor_SetActive(0, 1);

Definition at line 73 of file motor.c.

int Motor_SetDirection ( int  index,
char  forward 
)

Set the direction of a DC motor.

Parameters:
index An integer specifying which DC Motor (0-3).
forward A character specifying direction - 1/non-zero (forward) or 0 (reverse).
Returns:
Zero on success.
Example
  // Set the direction of motor 2 to reverse.
  Motor_SetDirection(2, 0);

Definition at line 151 of file motor.c.

int Motor_SetSpeed ( int  index,
int  duty 
)

Set the speed of a DC motor.

Parameters:
index An integer specifying which DC Motor (0-3).
duty An integer (0 - 1023) specifying the speed.
Returns:
Zero on success.
Example
  // Set the speed of motor 3 to %75
  Motor_SetSpeed(3, 768);

Definition at line 120 of file motor.c.