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

Dependencies:   mbed

Committer:
Dogcatfee
Date:
Wed Oct 25 00:05:33 2017 +0000
Revision:
3:41acca236570
Parent:
2:538f0e257365
Remove Errors, Use export friendly mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ziadeldebri 0:c542014a089d 1 #include "mbed.h"
ziadeldebri 1:4040dba1ef4c 2 #include "Motor.h"
ziadeldebri 1:4040dba1ef4c 3 /************************************* Lab4 Motor Control ***************************/
ziadeldebri 1:4040dba1ef4c 4 /* */
ziadeldebri 1:4040dba1ef4c 5 /* File: main.cpp */
ziadeldebri 1:4040dba1ef4c 6 /* Author: Ziad Eldebri */
ziadeldebri 1:4040dba1ef4c 7 /* Date Created: 7/22/2016 */
ziadeldebri 1:4040dba1ef4c 8 /* Description: This is the basic Lab4 code. It uses the position of the variable resistor
ziadeldebri 1:4040dba1ef4c 9 to control the motor speed and direction using L293 IC */
ziadeldebri 1:4040dba1ef4c 10 /* */
ziadeldebri 1:4040dba1ef4c 11 /****************************************************************************************/
ziadeldebri 2:538f0e257365 12 AnalogIn pot(PTB2); // variable resistor middile pin
ziadeldebri 2:538f0e257365 13 Motor my_motor(PTB1,PTB0); // create a motor object
ziadeldebri 0:c542014a089d 14
ziadeldebri 1:4040dba1ef4c 15
ziadeldebri 1:4040dba1ef4c 16 int main() {
ziadeldebri 0:c542014a089d 17
ziadeldebri 1:4040dba1ef4c 18 while (1) {
ziadeldebri 1:4040dba1ef4c 19
ziadeldebri 1:4040dba1ef4c 20 //Stop if in the middle
ziadeldebri 1:4040dba1ef4c 21 if((pot > 0.49) && (pot < 0.61)){
ziadeldebri 1:4040dba1ef4c 22 my_motor.Stop();
ziadeldebri 1:4040dba1ef4c 23 }
ziadeldebri 1:4040dba1ef4c 24 //Negative Direction
ziadeldebri 1:4040dba1ef4c 25 else if (pot < 0.48){
ziadeldebri 1:4040dba1ef4c 26 my_motor.Direction(LEFT);
ziadeldebri 1:4040dba1ef4c 27 wait(0.1);
ziadeldebri 1:4040dba1ef4c 28 }
ziadeldebri 1:4040dba1ef4c 29 //Postive Direction
ziadeldebri 1:4040dba1ef4c 30 else if (pot > 0.62 ) {
ziadeldebri 1:4040dba1ef4c 31 my_motor.Direction(RIGHT);
ziadeldebri 1:4040dba1ef4c 32 wait(0.1);
ziadeldebri 1:4040dba1ef4c 33 }
ziadeldebri 0:c542014a089d 34 }
ziadeldebri 1:4040dba1ef4c 35 }