basic motor controller class to be used with the TB6612 motor controller.
Diff: motor.cpp
- Revision:
- 0:322cf8e3ef05
diff -r 000000000000 -r 322cf8e3ef05 motor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motor.cpp Sun Oct 31 10:44:13 2021 +0000 @@ -0,0 +1,25 @@ +#include "motor.h" + +motor::motor(PinName dir1, PinName dir2, PinName motorOne): + dir1_(dir1), dir2_(dir2), motorOne_(motorOne) {} + +void motor::setSpeed(float speed){ + + if (speed > 0){ + dir1_ = true; + dir2_ = false; + motorOne_ = speed; + + } else { + dir1_ = false; + dir2_ = true; + motorOne_ = speed; + } +} + +motor & motor::operator = (float speed){ + setSpeed(speed); + return *this; +} + +