Control an H-Bridge using a PwmOut (enable) and two DigitalOuts (direction select)

Fork of Motor by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.cpp Source File

Motor.cpp

00001 
00002 #include "Motor.h"
00003 
00004 #include "mbed.h"
00005 
00006 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
00007         _pwm(pwm), _fwd(fwd), _rev(rev) {
00008 
00009     // Set initial condition of PWM
00010     _pwm.period(0.001);
00011     _pwm = 0;
00012 
00013     // Initial condition of output enables
00014     _fwd = 0;
00015     _rev = 0;
00016 }
00017 
00018 void Motor::speed(float speed) {
00019     _fwd = (speed > 0.0);
00020     _rev = (speed < 0.0);
00021     _pwm = abs(speed);
00022 }
00023 
00024 
00025