Difference between revisions of "ARDUINO MEGA Functions Motors and Servos"

From ROBOTC API Guide
Jump to: navigation, search
(motor)
Line 30: Line 30:
 
| class="variableType"| <span class="bigKeywordBI">int </span><span class="bigKeywordB">motor</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">tMotor motor</span><span class="bigCodePunc">]</span>
 
| class="variableType"| <span class="bigKeywordBI">int </span><span class="bigKeywordB">motor</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">tMotor motor</span><span class="bigCodePunc">]</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_int|int]]) An array variable with one element for each of the possible motors. This command is used to set the speed (-127 to +127) for a motor. Negative values are reverse; positive forward. Zero is stopped. To drive the motor on port1 at 50% of full power you use the statement motor[port1] = 63;
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_int|int]]) An array variable with one element for each of the possible motors.  
 +
 
 +
When used with a motor, this command is used to set the speed (-127 to +127) for a motor. Negative values are reverse; positive forward. Zero is stopped.
 +
 
 +
When used with a servo, this command is used to set the position (-127 to +127) of the servo. Zero is the "center" position of the servo, and -127 to +127 is the range of the servo. Note that your servo may not be able to travel the full -127 to +127 range, so please experiment with smaller values to avoid breaking your servo.
 
|-
 
|-
 
|
 
|

Revision as of 01:55, 10 May 2012

ARDUINOFunctions and Variables → ARDUINO MEGA Functions Motors and Servos


Color Key
Function:
Variable:


bMotorReflected

bool bMotorReflected
(bool) Boolean array with one entry for each motor. Indicates that the direction of a motor should be reflected 180 degrees. Useful when mechanical design results in a logical "reversed" condition of a motor.
bMotorReflected[motor_2] = true;   // motor 1 WILL be reflected 180 degrees
bMotorReflected[motor_2] = false;  // motor 1 will NOT be reflected 180 degrees


motor

int motor[tMotor motor]
(int) An array variable with one element for each of the possible motors.

When used with a motor, this command is used to set the speed (-127 to +127) for a motor. Negative values are reverse; positive forward. Zero is stopped.

When used with a servo, this command is used to set the position (-127 to +127) of the servo. Zero is the "center" position of the servo, and -127 to +127 is the range of the servo. Note that your servo may not be able to travel the full -127 to +127 range, so please experiment with smaller values to avoid breaking your servo.

Parameter Explanation Data Type
motor A motor port or name tMotor
motor[motor_2] = 127;   // motor pin 2 is given a power level of 127 (forward)
motor[motor_2] = -127;  // motor pin 2 is given a power level of -127 (reverse)