![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Maju
Diff: maju.cpp
- Revision:
- 0:8dbe4dae1b4a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maju.cpp Wed Mar 20 16:58:56 2019 +0000 @@ -0,0 +1,41 @@ +#include <iostream> +#include "m.bed" +#include "Motor.h" + +bool loop = true + +Motor::Motor(PinName pwm, PinName fwd, PinName rev): + _pwm(pwm), _fwd(fwd), _rev(rev) { + + // Set initial condition of PWM + _pwm.period(0.002); + _pwm = 0; + + // Initial condition of output enables + _fwd = 0; + _rev = 0; +} + +void Motor::speed(float speed) { + _fwd = (speed > (float)0.0); + _rev = (speed < (float)0.0); + _pwm = fabs(speed); +} + +void Motor::period(float period){ + + _pwm.period(period); + +} +int main () { + Motor MotorA (PC_7, PA_9, PA_8); + Motor MotorB (PA_7, PA_6, PA_5); + Motor MotorC (PB_3, PA_10, PA_2); + + while (loop == true) { + MotorA.speed (-0.5); + MotorB.speed (0.5); + } + + return 0; + } \ No newline at end of file