Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.cpp Source File

Motor.cpp

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