Chris Styles
/
mbedsumovore_logo
Diff: Motor.cpp
- Revision:
- 0:01a8e9b87e2f
diff -r 000000000000 -r 01a8e9b87e2f Motor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.cpp Sun Sep 20 23:27:39 2009 +0000 @@ -0,0 +1,32 @@ +#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); +} + + +