Dependencies:   mbed

Motor.cpp

Committer:
vcazan
Date:
2010-01-17
Revision:
0:552b174f8c2f

File content as of revision 0:552b174f8c2f:

#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 speed
 */
void Motor::speed(float speed) {
        _fwd = (speed > 0.0);
        _rev = (speed < 0.0);
        _pwm = abs(speed);
}