Skip to content
Noah Zemlin edited this page Oct 21, 2018 · 4 revisions

Motor

The Motor class represents physical motors.

Example code to create a motor and send output.

Motor motor;
motor.begin(4, 5, 3); //Initalize motor on digital pins 4 and 5, with PWM pin 3 as enable
motor.output(0.5); //Output half of max speed to the motor.

Constructors

Motor();

Default constructor.

Public Methods

Motor* begin(int in1pin, int in2pin);

Initalizes a 2 pin motor

Motor motor;
motor.begin(3,5); //Initalizes the motor on PWM pins 3 and 5

Motor* begin(int in1pin, int in2pin, int enpin);

Initalizes a 3 pin motor

Motor motor;
motor.begin(4,5,3); //Initalizes the motor on digital pins 4 and 5, and PWM pin 3.

Motor* setDefaultOnZero(int high);

Set the default signal to send to in1pin and in2pin on 0 speed. By default, this is set to HIGH.

Used for turning on brake or float. See Motor Controller datasheet for brake and float control logic.

Motor motor;
motor.begin(4,5,3); //Initalizes the motor on digital pins 4 and 5, and PWM pin 3.
motor.setDefaultOnZero(LOW); //When the speed is set to 0, LOW will be applied to both digital pins 3 and 4.

void output(float speed);

Output a speed to the motor, between -1 and 1.

Speed of 0 outputs LOW or HIGH to both in1pin and in2pin based on setDefaultOnZero(). The default is HIGH.

Motor motor;
motor.begin(4, 5, 3); //Initalize motor on digital pins 4 and 5, with PWM pin 3 as enable
motor.output(0.5); //Output half of max speed to the motor.

void outputBool(int high);

Sends LOW or HIGH to both in1pin and in2pin.

Used for turning on brake or float. See Motor Controller datasheet for brake and float control logic.

Motor motor;
motor.begin(4, 5, 3); //Initalize motor on digital pins 4 and 5, with PWM pin 3 as enable
motor.outputBool(LOW); //Output LOW to both digital pins 4 and 5
Clone this wiki locally