Control an H-Bridge using a PwmOut (enable) and two DigitalOuts (direction select)
Fork of Motor by
Diff: Motor.cpp
- Revision:
- 3:9572ea41a1b4
- Parent:
- 2:f265e441bcd9
- Child:
- 4:5370aae8ee3b
diff -r f265e441bcd9 -r 9572ea41a1b4 Motor.cpp --- a/Motor.cpp Tue Nov 23 16:16:43 2010 +0000 +++ b/Motor.cpp Thu May 07 09:45:03 2015 +0000 @@ -25,7 +25,8 @@ #include "mbed.h" Motor::Motor(PinName pwm, PinName fwd, PinName rev): - _pwm(pwm), _fwd(fwd), _rev(rev) { + _pwm(pwm), _fwd(fwd), _rev(rev) +{ // Set initial condition of PWM _pwm.period(0.001); @@ -36,9 +37,18 @@ _rev = 0; } -void Motor::speed(float speed) { - _fwd = (speed > 0.0); - _rev = (speed < 0.0); +void Motor::speed(float speed) +{ + /*if(speed>0) { + _fwd = 1; + _rev = 0; + } + if(speed<0) { + _fwd = 0; + _rev = 1; + }*/ + _fwd = 0; + _rev = 1; _pwm = abs(speed); }