Dependencies:   mbed

Motor.cpp

Committer:
chris
Date:
2009-09-20
Revision:
0:01a8e9b87e2f

File content as of revision 0:01a8e9b87e2f:

#include "Motor.h"
#include "mbed.h"


// ==================================================================
// Constructor
// ==================================================================
Motor::Motor(PinName pwm, PinName fwd, PinName rev): 
    _pwm(pwm), _fwd(fwd), _rev(rev) {    
    
    // Set initial condition of PWM
    _pwm.period(0.001);
    _pwm = 0;

    // Initial condition of output enables
    _fwd = 0;
    _rev = 0;

}

    
// ==================================================================
// Set the motor speed and direction
// ==================================================================
void Motor::speed(float speed) {
        _fwd = (speed > 0.0);
        _rev = (speed < 0.0);
        _pwm = abs(speed);
}