basic motor controller class to be used with the TB6612 motor controller.
Revision 0:322cf8e3ef05, committed 2021-10-31
- Comitter:
- snapo
- Date:
- Sun Oct 31 10:44:13 2021 +0000
- Commit message:
- initial motor controller class for use in a maze solving robot
Changed in this revision
motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
motor.h | Show annotated file Show diff for this revision Revisions of this file |
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; +} + +
diff -r 000000000000 -r 322cf8e3ef05 motor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motor.h Sun Oct 31 10:44:13 2021 +0000 @@ -0,0 +1,22 @@ +#pragma once +#include "mbed.h" + + +class motor { + DigitalOut dir1_ ; + DigitalOut dir2_ ; + PwmOut motorOne_ ; + + public: + + + + motor(PinName dir1, PinName dir2, PinName motorOne); + + void setSpeed (float speed); + + motor & operator= (float speed); + + + +}; \ No newline at end of file