Simple motor controller library, using DIR, PWM, nSLP pin like pololu.
Diff: MotorControler.cpp
- Revision:
- 1:ed3dfe4ecc8a
- Parent:
- 0:e3207dd7809a
- Child:
- 2:543ff0150de1
diff -r e3207dd7809a -r ed3dfe4ecc8a MotorControler.cpp --- a/MotorControler.cpp Wed Mar 04 03:53:06 2020 +0000 +++ b/MotorControler.cpp Wed Mar 04 04:05:35 2020 +0000 @@ -3,6 +3,7 @@ MotorControler::MotorControler(PinName DIR, PinName PWM, PinName SLP) : _DIR(DIR), _PWM(PWM), _nSLP(SLP) { _nSLP = 0; + reverse_direction = 0; } void MotorControler::enableDriver() @@ -28,7 +29,7 @@ speed = 1; _PWM = speed; - if (reverse ^ FLIP_MOTOR_DIR) + if (reverse ^ FLIP_MOTOR_DIR ^ reverse_direction) { _DIR = 1; } @@ -36,4 +37,9 @@ { _DIR = 0; } +} + +void MotorControler::setMotorDirection(MotorDirection dir) +{ + reverse_direction = dir; } \ No newline at end of file