For all the code presented here, the include file
  #include "direct-motor.h"
will need to called out in the source.

Each of the motor output ports can be set to one of 4 states:

off motors freewheel and use no power
fwd forward rotation
rev backward rotation
brake motor shorted, uses some power
and the speed is controllable from MIN_SPEED to MAX_SPEED (currently 255 steps). Note: MIN_SPEED will not be always usable depending on the rolling resistance of the mechanism, floor type and slope for rovers, etc.

The motor to drive is specified by the name of the function that is called out:

  motor_X_speed()
  motor_X_dir()
where X is a,b,or c

To setup and drive a motor:

  /* drive motor A forward at half speed */
  motor_a_speed(MAX_SPEED/2);
  motor_a_dir(fwd);
It is quite usable to set the motor speed at initialization and then to use the direction control to turn the motors on and off as needed.
Previous - Sensors Main Next - Front Panel
Monty Stein Dec 18, 1999
CLUG Home