Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Motor by
Revision 3:7f1fd2d62c72, committed 2014-02-27
- Comitter:
- cbradford
- Date:
- Thu Feb 27 01:40:41 2014 +0000
- Parent:
- 2:f265e441bcd9
- Commit message:
- Changed the Motor.cpp and Motor.h to deal with two PWMs, instead of 1 PWM and 2 Digital
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 |
--- a/Motor.cpp Tue Nov 23 16:16:43 2010 +0000 +++ b/Motor.cpp Thu Feb 27 01:40:41 2014 +0000 @@ -24,22 +24,21 @@ #include "mbed.h" -Motor::Motor(PinName pwm, PinName fwd, PinName rev): - _pwm(pwm), _fwd(fwd), _rev(rev) { - - // Set initial condition of PWM - _pwm.period(0.001); - _pwm = 0; +Motor::Motor(PinName fwd, PinName rev): + _fwd(fwd), _rev(rev) { // Initial condition of output enables _fwd = 0; + _fwd.period(0.001); _rev = 0; + _rev.period(0.001); } void Motor::speed(float speed) { - _fwd = (speed > 0.0); - _rev = (speed < 0.0); - _pwm = abs(speed); + if(speed > 0.0) + _fwd = abs(speed); + else + _rev = abs(speed); }
--- a/Motor.h Tue Nov 23 16:16:43 2010 +0000 +++ b/Motor.h Thu Feb 27 01:40:41 2014 +0000 @@ -34,11 +34,10 @@ /** Create a motor control interface * - * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed - * @param fwd A DigitalOut, set high when the motor should go forward - * @param rev A DigitalOut, set high when the motor should go backwards + * @param fwd A PwmOut pin, set value when the motor should go forward + * @param rev A PwmOut pin, set value when the motor should go backwards */ - Motor(PinName pwm, PinName fwd, PinName rev); + Motor(PinName fwd, PinName rev); /** Set the speed of the motor * @@ -47,10 +46,8 @@ void speed(float speed); protected: - PwmOut _pwm; - DigitalOut _fwd; - DigitalOut _rev; - + PwmOut _fwd; + PwmOut _rev; }; #endif