Dependencies:   mbed

Committer:
vcazan
Date:
Sun Jan 17 17:17:06 2010 +0000
Revision:
0:552b174f8c2f

        

Who changed what in which revision?

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