Maju

Dependencies:   mbed Motor

Committer:
RickyLinarto
Date:
Wed Mar 20 16:58:56 2019 +0000
Revision:
0:8dbe4dae1b4a
Maju

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RickyLinarto 0:8dbe4dae1b4a 1 #include <iostream>
RickyLinarto 0:8dbe4dae1b4a 2 #include "m.bed"
RickyLinarto 0:8dbe4dae1b4a 3 #include "Motor.h"
RickyLinarto 0:8dbe4dae1b4a 4
RickyLinarto 0:8dbe4dae1b4a 5 bool loop = true
RickyLinarto 0:8dbe4dae1b4a 6
RickyLinarto 0:8dbe4dae1b4a 7 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
RickyLinarto 0:8dbe4dae1b4a 8 _pwm(pwm), _fwd(fwd), _rev(rev) {
RickyLinarto 0:8dbe4dae1b4a 9
RickyLinarto 0:8dbe4dae1b4a 10 // Set initial condition of PWM
RickyLinarto 0:8dbe4dae1b4a 11 _pwm.period(0.002);
RickyLinarto 0:8dbe4dae1b4a 12 _pwm = 0;
RickyLinarto 0:8dbe4dae1b4a 13
RickyLinarto 0:8dbe4dae1b4a 14 // Initial condition of output enables
RickyLinarto 0:8dbe4dae1b4a 15 _fwd = 0;
RickyLinarto 0:8dbe4dae1b4a 16 _rev = 0;
RickyLinarto 0:8dbe4dae1b4a 17 }
RickyLinarto 0:8dbe4dae1b4a 18
RickyLinarto 0:8dbe4dae1b4a 19 void Motor::speed(float speed) {
RickyLinarto 0:8dbe4dae1b4a 20 _fwd = (speed > (float)0.0);
RickyLinarto 0:8dbe4dae1b4a 21 _rev = (speed < (float)0.0);
RickyLinarto 0:8dbe4dae1b4a 22 _pwm = fabs(speed);
RickyLinarto 0:8dbe4dae1b4a 23 }
RickyLinarto 0:8dbe4dae1b4a 24
RickyLinarto 0:8dbe4dae1b4a 25 void Motor::period(float period){
RickyLinarto 0:8dbe4dae1b4a 26
RickyLinarto 0:8dbe4dae1b4a 27 _pwm.period(period);
RickyLinarto 0:8dbe4dae1b4a 28
RickyLinarto 0:8dbe4dae1b4a 29 }
RickyLinarto 0:8dbe4dae1b4a 30 int main () {
RickyLinarto 0:8dbe4dae1b4a 31 Motor MotorA (PC_7, PA_9, PA_8);
RickyLinarto 0:8dbe4dae1b4a 32 Motor MotorB (PA_7, PA_6, PA_5);
RickyLinarto 0:8dbe4dae1b4a 33 Motor MotorC (PB_3, PA_10, PA_2);
RickyLinarto 0:8dbe4dae1b4a 34
RickyLinarto 0:8dbe4dae1b4a 35 while (loop == true) {
RickyLinarto 0:8dbe4dae1b4a 36 MotorA.speed (-0.5);
RickyLinarto 0:8dbe4dae1b4a 37 MotorB.speed (0.5);
RickyLinarto 0:8dbe4dae1b4a 38 }
RickyLinarto 0:8dbe4dae1b4a 39
RickyLinarto 0:8dbe4dae1b4a 40 return 0;
RickyLinarto 0:8dbe4dae1b4a 41 }