Committer:
inst
Date:
Sun Nov 29 11:39:13 2015 +0000
Revision:
1:5a14412eb231
Parent:
0:479438556d43

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:479438556d43 1 #ifndef INCLUDED_MOTOR_H
inst 0:479438556d43 2 #define INCLUDED_MOTOR_H
inst 0:479438556d43 3
inst 0:479438556d43 4 #include "mbed.h"
inst 0:479438556d43 5
inst 0:479438556d43 6 // p0 p3
inst 0:479438556d43 7 // | |
inst 0:479438556d43 8 // |--M--|
inst 0:479438556d43 9 // | |
inst 0:479438556d43 10 // p1 p2
inst 0:479438556d43 11 class Motor{
inst 0:479438556d43 12 public:
inst 0:479438556d43 13 enum ActionType{
inst 0:479438556d43 14 FORWARD,
inst 0:479438556d43 15 BACKWARD,
inst 0:479438556d43 16 BRAKE,
inst 0:479438556d43 17 RELEASE
inst 0:479438556d43 18 };
inst 0:479438556d43 19
inst 0:479438556d43 20 Motor( PinName p0, PinName p1, PinName p2, PinName p3 );
inst 0:479438556d43 21 ~Motor();
inst 0:479438556d43 22
inst 0:479438556d43 23 void setPercent( float p ){
inst 0:479438556d43 24 setDuty( mMinDuty + ( mMaxDuty - mMinDuty ) * p );
inst 0:479438556d43 25 }
inst 0:479438556d43 26 void setDuty( float d ){
inst 0:479438556d43 27 if ( d > mMaxDuty ){
inst 0:479438556d43 28 d = mMaxDuty;
inst 0:479438556d43 29 } else if ( d < mMinDuty ){
inst 0:479438556d43 30 d = mMinDuty;
inst 0:479438556d43 31 }
inst 0:479438556d43 32 mDuty = d;
inst 0:479438556d43 33
inst 0:479438556d43 34 update();
inst 0:479438556d43 35 }
inst 0:479438556d43 36 void setActionType( ActionType a ){
inst 0:479438556d43 37 mActionType = a;
inst 0:479438556d43 38 update();
inst 0:479438556d43 39 }
inst 0:479438556d43 40
inst 0:479438556d43 41 private:
inst 0:479438556d43 42 void update();
inst 0:479438556d43 43
inst 0:479438556d43 44 static const float mMinDuty;
inst 0:479438556d43 45 static const float mMaxDuty;
inst 0:479438556d43 46
inst 0:479438556d43 47 float mDuty;
inst 0:479438556d43 48 ActionType mActionType;
inst 0:479438556d43 49
inst 0:479438556d43 50 PwmOut* mPin0_PWM;
inst 0:479438556d43 51 DigitalOut* mPin1_D;
inst 0:479438556d43 52 DigitalOut* mPin2_D;
inst 0:479438556d43 53 PwmOut* mPin3_PWM;
inst 0:479438556d43 54 };
inst 0:479438556d43 55
inst 0:479438556d43 56 #endif