Mouse code for the MacroRat
motor.cpp
- Committer:
- kyleliangus
- Date:
- 2017-05-12
- Revision:
- 12:5790e56a056f
- Parent:
- 8:a0760acdc59e
- Child:
- 13:2032db00f168
File content as of revision 12:5790e56a056f:
#include "mbed.h" #include "motor.h" void Motor::backward(double voltage) { if(voltage > maxSpeed){ voltage = maxSpeed; }else if(voltage < 0){ voltage = 0.0; } forw.write(voltage); back.write(0); } void Motor::forward(double voltage) { if(voltage > maxSpeed){ voltage = maxSpeed; }else if(voltage < 0){ voltage = 0.0; } forw.write(0); back.write(voltage); } void Motor::move(double voltage) { if(voltage < 0){ backward(voltage); } if(voltage > 0){ forward(voltage); } } void Motor::brake() { forw.write(BRAKE_VOLTAGE); back.write(BRAKE_VOLTAGE); } void Motor::coast() { forw.write(0); back.write(0); }