Library for driving a motor with one PWM and one DIR signal using PI control.
Fork of Motor2 by
Diff: motor.cpp
- Revision:
- 11:87a73d40ce5b
- Parent:
- 10:b0e6051a6109
- Child:
- 12:1d3fb22bbdf9
--- a/motor.cpp Sun Nov 03 11:41:40 2013 +0000 +++ b/motor.cpp Sun Oct 19 08:31:18 2014 +0000 @@ -1,7 +1,7 @@ #include "motor.h" -Motor::Motor(PinName PWMpin, PCA9555 *ioExt, unsigned int dir1Pin, unsigned int dir2Pin, PinName encA, PinName encB) - : pwm(PWMpin), extIO(ioExt), dir1(dir1Pin), dir2(dir2Pin), qed(encA, encB) { +Motor::Motor(PinName PWMpin, PCA9555 *ioExt, unsigned int dirPin, PinName encA, PinName encB) + : pwm(PWMpin), extIO(ioExt), dir(dirPin), qed(encA, encB) { pwmPeriod = 2500; PwmOut pwm(PWMpin); @@ -32,13 +32,11 @@ currentPWM = newPWM; if (newPWM < 0) { pwm.pulsewidth_us(-1 * newPWM); - extIO->setPin(dir1); - extIO->clearPin(dir2); + extIO->setPin(dir); } else { pwm.pulsewidth_us(newPWM); - extIO->clearPin(dir1); - extIO->setPin(dir2); - } + extIO->clearPin(dir); + } } int Motor::getSpeed() {