demo demo
/
BluetoothSumo
Motor.cpp@0:41f85a3f645d, 2009-09-19 (annotated)
- Committer:
- demo
- Date:
- Sat Sep 19 18:32:13 2009 +0000
- Revision:
- 0:41f85a3f645d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
demo | 0:41f85a3f645d | 1 | // H-Bridge Motor Control |
demo | 0:41f85a3f645d | 2 | // Copyright (c) 2009 sford |
demo | 0:41f85a3f645d | 3 | // Released under the MIT License: http://mbed.org/license/mit |
demo | 0:41f85a3f645d | 4 | |
demo | 0:41f85a3f645d | 5 | #include "Motor.h" |
demo | 0:41f85a3f645d | 6 | |
demo | 0:41f85a3f645d | 7 | #include "mbed.h" |
demo | 0:41f85a3f645d | 8 | |
demo | 0:41f85a3f645d | 9 | Motor::Motor(PinName pwm, PinName fwd, PinName rev) : _pwm(pwm), _fwd(fwd), _rev(rev) { |
demo | 0:41f85a3f645d | 10 | |
demo | 0:41f85a3f645d | 11 | // Set initial condition of PWM |
demo | 0:41f85a3f645d | 12 | _pwm.period(0.001); |
demo | 0:41f85a3f645d | 13 | _pwm = 0; |
demo | 0:41f85a3f645d | 14 | |
demo | 0:41f85a3f645d | 15 | // Initial condition of output enables |
demo | 0:41f85a3f645d | 16 | _fwd = 0; |
demo | 0:41f85a3f645d | 17 | _rev = 0; |
demo | 0:41f85a3f645d | 18 | } |
demo | 0:41f85a3f645d | 19 | |
demo | 0:41f85a3f645d | 20 | void Motor::speed(float speed) { |
demo | 0:41f85a3f645d | 21 | _fwd = (speed > 0.0); |
demo | 0:41f85a3f645d | 22 | _rev = (speed < 0.0); |
demo | 0:41f85a3f645d | 23 | _pwm = abs(speed); |
demo | 0:41f85a3f645d | 24 | } |