Motor.cpp
- Committer:
- demo
- Date:
- 2009-09-19
- Revision:
- 0:41f85a3f645d
File content as of revision 0:41f85a3f645d:
// H-Bridge Motor Control
// Copyright (c) 2009 sford
// Released under the MIT License: http://mbed.org/license/mit
#include "Motor.h"
#include "mbed.h"
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;
}
void Motor::speed(float speed) {
_fwd = (speed > 0.0);
_rev = (speed < 0.0);
_pwm = abs(speed);
}