![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Teacher version
Dependencies: mbed lib_workshop_2019
src/test_motor/ft_run_motor.cpp@5:d99659a45cab, 2019-10-24 (annotated)
- Committer:
- gvaquette
- Date:
- Thu Oct 24 03:54:20 2019 +0000
- Revision:
- 5:d99659a45cab
- Parent:
- 4:bf5caf4c0c88
Before first student version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gvaquette | 4:bf5caf4c0c88 | 1 | #include "mbed.h" |
gvaquette | 4:bf5caf4c0c88 | 2 | #include "test_motor.h" |
gvaquette | 4:bf5caf4c0c88 | 3 | |
gvaquette | 5:d99659a45cab | 4 | /**********************************************************************/ |
gvaquette | 5:d99659a45cab | 5 | /** ft_run_motor **/ |
gvaquette | 5:d99659a45cab | 6 | /* Args : - direction (e_direction): direction to turn the motor */ |
gvaquette | 5:d99659a45cab | 7 | /* - duty_cycle (double): duty cycle for the PWM */ |
gvaquette | 5:d99659a45cab | 8 | /* - pwm_mot (PwmOut): pin to set the PWM */ |
gvaquette | 5:d99659a45cab | 9 | /* - dirA and dirB (DigitalOut): Pins to set the direction */ |
gvaquette | 5:d99659a45cab | 10 | /**********************************************************************/ |
gvaquette | 4:bf5caf4c0c88 | 11 | void ft_run_motor( e_direction direction, double duty_cycle, |
gvaquette | 4:bf5caf4c0c88 | 12 | PwmOut pwm_mot, DigitalOut dirA, DigitalOut dirB) |
gvaquette | 4:bf5caf4c0c88 | 13 | { |
gvaquette | 4:bf5caf4c0c88 | 14 | |
gvaquette | 4:bf5caf4c0c88 | 15 | /* TO DO : define direction */ |
gvaquette | 4:bf5caf4c0c88 | 16 | |
gvaquette | 4:bf5caf4c0c88 | 17 | if (direction == FORWARD) |
gvaquette | 4:bf5caf4c0c88 | 18 | { |
gvaquette | 4:bf5caf4c0c88 | 19 | dirA = 1; |
gvaquette | 4:bf5caf4c0c88 | 20 | dirB = 0; |
gvaquette | 4:bf5caf4c0c88 | 21 | } |
gvaquette | 4:bf5caf4c0c88 | 22 | else // direction == BACKWARD |
gvaquette | 4:bf5caf4c0c88 | 23 | { |
gvaquette | 4:bf5caf4c0c88 | 24 | dirA = 0; |
gvaquette | 4:bf5caf4c0c88 | 25 | dirB = 1; |
gvaquette | 4:bf5caf4c0c88 | 26 | } |
gvaquette | 4:bf5caf4c0c88 | 27 | |
gvaquette | 5:d99659a45cab | 28 | /* TO DO : apply duty cycle to pwm_mot */ |
gvaquette | 4:bf5caf4c0c88 | 29 | pwm_mot = duty_cycle; |
gvaquette | 4:bf5caf4c0c88 | 30 | } |