Create a motor object, to control a motor using L293DNE and FDRM-KL46z.

Dependencies:   mbed

Committer:
ziadeldebri
Date:
Fri Oct 21 16:39:10 2016 +0000
Revision:
2:538f0e257365
Parent:
1:4040dba1ef4c
Child:
3:41acca236570
less wires

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ziadeldebri 0:c542014a089d 1 #include "mbed.h"
ziadeldebri 0:c542014a089d 2 #include "Motor.h"
ziadeldebri 0:c542014a089d 3
ziadeldebri 2:538f0e257365 4 Motor::Motor(PinName Positive, PinName Negative): _positive(Positive), _negative(Negative){
ziadeldebri 2:538f0e257365 5 _positive.period(0.03f); // 4 second period
ziadeldebri 2:538f0e257365 6 _positive.write(0.25f);
ziadeldebri 2:538f0e257365 7 _negative.period(0.03f); // 4 second period
ziadeldebri 2:538f0e257365 8 _negative.write(0.25f);
ziadeldebri 2:538f0e257365 9
ziadeldebri 0:c542014a089d 10 }
ziadeldebri 1:4040dba1ef4c 11 /* Input 1 or 2 or LEFT and RIGHT
ziadeldebri 0:c542014a089d 12 * 1 : Postive VCC Negtaive GND, 2 : Postive GND Negtaive VCC.
ziadeldebri 0:c542014a089d 13 */
ziadeldebri 0:c542014a089d 14 void Motor::Direction(int move) {
ziadeldebri 0:c542014a089d 15 if(move == 1){
ziadeldebri 0:c542014a089d 16 _positive = 1;
ziadeldebri 0:c542014a089d 17 _negative = 0;
ziadeldebri 0:c542014a089d 18 }
ziadeldebri 0:c542014a089d 19 else if(move == 2){
ziadeldebri 0:c542014a089d 20 _positive = 0;
ziadeldebri 0:c542014a089d 21 _negative = 1;
ziadeldebri 0:c542014a089d 22 }
ziadeldebri 0:c542014a089d 23 }//End of Direction
ziadeldebri 0:c542014a089d 24
ziadeldebri 0:c542014a089d 25 /* No input.
ziadeldebri 0:c542014a089d 26 * 1 : Postive GND Negtaive GND
ziadeldebri 0:c542014a089d 27 */
ziadeldebri 0:c542014a089d 28 void Motor::Stop() {
ziadeldebri 0:c542014a089d 29 _positive = 0;
ziadeldebri 0:c542014a089d 30 _negative = 0;
ziadeldebri 0:c542014a089d 31 }//End of Stop
ziadeldebri 0:c542014a089d 32
ziadeldebri 0:c542014a089d 33 void Motor::Speed(int motor_speed) {
ziadeldebri 0:c542014a089d 34 float percantage = motor_speed/100;
ziadeldebri 2:538f0e257365 35
ziadeldebri 0:c542014a089d 36 }//End of Speed