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

Dependencies:   mbed

Committer:
ziadeldebri
Date:
Fri Aug 19 02:10:52 2016 +0000
Revision:
1:4040dba1ef4c
Parent:
0:c542014a089d
Child:
2:538f0e257365
fixed comments

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 0:c542014a089d 4 Motor::Motor(PinName Positive, PinName Negative,PinName Speed):
ziadeldebri 0:c542014a089d 5 _positive(Positive), _negative(Negative), _speed(Speed) {
ziadeldebri 0:c542014a089d 6 _speed.period(0.03f); // 4 second period
ziadeldebri 0:c542014a089d 7 _speed.write(0.20f);
ziadeldebri 0:c542014a089d 8 }
ziadeldebri 1:4040dba1ef4c 9 /* Input 1 or 2 or LEFT and RIGHT
ziadeldebri 0:c542014a089d 10 * 1 : Postive VCC Negtaive GND, 2 : Postive GND Negtaive VCC.
ziadeldebri 0:c542014a089d 11 */
ziadeldebri 0:c542014a089d 12 void Motor::Direction(int move) {
ziadeldebri 0:c542014a089d 13 if(move == 1){
ziadeldebri 0:c542014a089d 14 _positive = 1;
ziadeldebri 0:c542014a089d 15 _negative = 0;
ziadeldebri 0:c542014a089d 16 }
ziadeldebri 0:c542014a089d 17 else if(move == 2){
ziadeldebri 0:c542014a089d 18 _positive = 0;
ziadeldebri 0:c542014a089d 19 _negative = 1;
ziadeldebri 0:c542014a089d 20 }
ziadeldebri 0:c542014a089d 21 }//End of Direction
ziadeldebri 0:c542014a089d 22
ziadeldebri 0:c542014a089d 23 /* No input.
ziadeldebri 0:c542014a089d 24 * 1 : Postive GND Negtaive GND
ziadeldebri 0:c542014a089d 25 */
ziadeldebri 0:c542014a089d 26 void Motor::Stop() {
ziadeldebri 0:c542014a089d 27 _positive = 0;
ziadeldebri 0:c542014a089d 28 _negative = 0;
ziadeldebri 0:c542014a089d 29 }//End of Stop
ziadeldebri 0:c542014a089d 30
ziadeldebri 0:c542014a089d 31 void Motor::Speed(int motor_speed) {
ziadeldebri 0:c542014a089d 32 float percantage = motor_speed/100;
ziadeldebri 0:c542014a089d 33 _speed.write(percantage);
ziadeldebri 0:c542014a089d 34 }//End of Speed