UNFINISHED
Dependencies: HCSR04 SRF05 mbed
motor.h
- Committer:
- Charlie_He
- Date:
- 2018-06-08
- Revision:
- 0:4ca3e247b86a
- Child:
- 1:60c79e942c98
File content as of revision 0:4ca3e247b86a:
#ifndef MOTOR_H #define MOTOR_H #include "mbed.h" class Motor { public: Motor(DigitalOut ma,DigitalOut mb,PwmOut ms) : motorA(ma),motorB(mb),motorS(ms),motorSpeed(0),direction(0) {} Motor(PinName pa,PinName pb,PinName ps) : motorA(DigitalOut(pa)),motorB(DigitalOut(pb)),motorS(PwmOut(ps)),motorSpeed(0),direction(0) {} void setSpeed(float speed); void setDefaultDirection(int dir) { direction = dir; } void operator = (float f){ setSpeed(f); } operator float(){ return motorSpeed; } private: DigitalOut motorA,motorB; PwmOut motorS; float motorSpeed; int direction; }; void Motor::setSpeed(float speed) { if(speed > 0) { motorA = direction?1:0; motorB = direction?0:1; } else { motorA = direction?0:1; motorB = direction?1:0; } motorSpeed = speed; motorS = abs(speed); } #endif