Control an H-Bridge using a PwmOut (enable) and two DigitalOuts (direction select)
Fork of Motor by
Motor.cpp
- Committer:
- pr0jelly
- Date:
- 2016-09-26
- Revision:
- 3:6da484a06159
- Parent:
- 2:f265e441bcd9
File content as of revision 3:6da484a06159:
#include "Motor.h" #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; // Initial condition of output enables _fwd = 0; _rev = 0; } void Motor::speed(float speed) { _fwd = (speed > 0.0); _rev = (speed < 0.0); _pwm = abs(speed); }