v1
Dependencies: PinDetect TextLCD mbed
Fork of SunflowerMach1 by
MotorDrivers/Motor.cpp
- Committer:
- mdraganic
- Date:
- 2013-11-09
- Revision:
- 3:bebfc64cefe4
- Parent:
- 1:3500bf8487d0
- Child:
- 4:03b68322905f
File content as of revision 3:bebfc64cefe4:
#include "Motor.h" Motor::Motor(PinName positivePin, PinName negativePin, PinName pwmPin): positiveOut(positivePin), negativeOut(negativePin), pwmOut(pwmPin) { pwmOut.period(motorPwmPeriod); pwmOut = motorPwmInitDutyCycle; positiveOut = 0; negativeOut = 0; _isMoving = false; } void Motor::movePositive() { direction = 1; move(); } void Motor::moveNegative() { direction = -1; move(); } void Motor::move() { positiveOut = 0; negativeOut = 0; switch(direction) { case 0: return; case 1: positiveOut = 1; break; case -1: negativeOut = 1; break; } for (float i = 1; i > 0; i -= motorPwmChangeSpeed) { pwmOut = i; wait(motorPwmWaitTime); } pwmOut = 0; _isMoving = true; // wait_ms(motorDriveTime); // stop(); } void Motor::stop() { for (float i = 0; i < 1; i += motorPwmChangeSpeed) { pwmOut = i; wait(motorPwmWaitTime); } pwmOut = 1; positiveOut = 0; negativeOut = 0; direction = 0; _isMoving = false; } bool Motor::isMoving() { return _isMoving; }