Dependencies:   mbed

Committer:
chris
Date:
Sun Sep 20 23:27:39 2009 +0000
Revision:
0:01a8e9b87e2f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:01a8e9b87e2f 1 #include "Motor.h"
chris 0:01a8e9b87e2f 2 #include "mbed.h"
chris 0:01a8e9b87e2f 3
chris 0:01a8e9b87e2f 4
chris 0:01a8e9b87e2f 5 // ==================================================================
chris 0:01a8e9b87e2f 6 // Constructor
chris 0:01a8e9b87e2f 7 // ==================================================================
chris 0:01a8e9b87e2f 8 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
chris 0:01a8e9b87e2f 9 _pwm(pwm), _fwd(fwd), _rev(rev) {
chris 0:01a8e9b87e2f 10
chris 0:01a8e9b87e2f 11 // Set initial condition of PWM
chris 0:01a8e9b87e2f 12 _pwm.period(0.001);
chris 0:01a8e9b87e2f 13 _pwm = 0;
chris 0:01a8e9b87e2f 14
chris 0:01a8e9b87e2f 15 // Initial condition of output enables
chris 0:01a8e9b87e2f 16 _fwd = 0;
chris 0:01a8e9b87e2f 17 _rev = 0;
chris 0:01a8e9b87e2f 18
chris 0:01a8e9b87e2f 19 }
chris 0:01a8e9b87e2f 20
chris 0:01a8e9b87e2f 21
chris 0:01a8e9b87e2f 22 // ==================================================================
chris 0:01a8e9b87e2f 23 // Set the motor speed and direction
chris 0:01a8e9b87e2f 24 // ==================================================================
chris 0:01a8e9b87e2f 25 void Motor::speed(float speed) {
chris 0:01a8e9b87e2f 26 _fwd = (speed > 0.0);
chris 0:01a8e9b87e2f 27 _rev = (speed < 0.0);
chris 0:01a8e9b87e2f 28 _pwm = abs(speed);
chris 0:01a8e9b87e2f 29 }
chris 0:01a8e9b87e2f 30
chris 0:01a8e9b87e2f 31
chris 0:01a8e9b87e2f 32