Simple motor controller library, using DIR, PWM, nSLP pin like pololu.
Diff: MotorControler.cpp
- Revision:
- 3:7acc824ca344
- Parent:
- 2:543ff0150de1
- Child:
- 4:a60052db674c
--- a/MotorControler.cpp Wed Mar 04 06:13:26 2020 +0000 +++ b/MotorControler.cpp Tue Feb 02 13:51:29 2021 +0000 @@ -1,19 +1,19 @@ #include "MotorControler.h" -MotorControler::MotorControler(PinName DIR, PinName PWM, PinName SLP) : _DIR(DIR), _PWM(PWM), _nSLP(SLP) +MotorControler::MotorControler(PinName DIR, PinName PWM, PinName SLP, DriverType) : DIR_(DIR), PWM_(PWM), nSLP_(SLP) { - _nSLP = 0; - reverse_direction = 0; + nSLP_ = 0; + reverse_direction_ = 0; } void MotorControler::enableDriver() { - _nSLP = 1; + nSLP_ = 1; } void MotorControler::disableDriver() { - _nSLP = 0; + nSLP_ = 0; } void MotorControler::setSpeed(float speed) @@ -28,24 +28,24 @@ if (speed > 1) speed = 1; - _PWM = speed; - if (reverse ^ FLIP_MOTOR_DIR ^ reverse_direction) + PWM_ = speed; + if (reverse ^ FLIP_MOTOR_DIR ^ reverse_direction_) { - _DIR = 1; + DIR_ = 1; } else { - _DIR = 0; + DIR_ = 0; } } void MotorControler::setMotorDirection(MotorDirection dir) { - reverse_direction = dir; + reverse_direction_ = dir; } void MotorControler::setPwmFrequency(float frequency) { float period = 1.0/frequency; - _PWM.period(period); + PWM_.period(period); } \ No newline at end of file