ggg

Dependencies:   Motor mbed

Committer:
matthewhall115
Date:
Fri Mar 09 02:54:18 2018 +0000
Revision:
0:4345759be364
yo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matthewhall115 0:4345759be364 1 #include "mbed.h"
matthewhall115 0:4345759be364 2 #include "Motor.h" // program to drive DC motor
matthewhall115 0:4345759be364 3 #define PI (3.14159) //define PI to make life easy
matthewhall115 0:4345759be364 4
matthewhall115 0:4345759be364 5 PwmOut led(LED2); //define led
matthewhall115 0:4345759be364 6 Motor m(p21,p22,p22); //define pins for MBED/TD340 communication
matthewhall115 0:4345759be364 7
matthewhall115 0:4345759be364 8 //Declare global variables for data handling
matthewhall115 0:4345759be364 9 char c; //declaring character 'c'
matthewhall115 0:4345759be364 10 float dc; //float called dc, duty cycle
matthewhall115 0:4345759be364 11
matthewhall115 0:4345759be364 12 int main () //main function
matthewhall115 0:4345759be364 13 {
matthewhall115 0:4345759be364 14
matthewhall115 0:4345759be364 15
matthewhall115 0:4345759be364 16 while(1) {
matthewhall115 0:4345759be364 17 led=0; //LED off
matthewhall115 0:4345759be364 18 m.speed(0); //motor is off
matthewhall115 0:4345759be364 19 c = getchar(); //get character inpput from user
matthewhall115 0:4345759be364 20
matthewhall115 0:4345759be364 21
matthewhall115 0:4345759be364 22 if (c == 'l') { //if the character 'l' is pressed
matthewhall115 0:4345759be364 23 led != led;
matthewhall115 0:4345759be364 24 printf("Enter Duty Cycle in +0.XX form to move left: \n\n"); //asking for user input
matthewhall115 0:4345759be364 25 scanf("%f", &dc); //storing user input
matthewhall115 0:4345759be364 26 puts("Moving left!\n\n");
matthewhall115 0:4345759be364 27 m.speed(dc); //moving the motor at the user's desired duty cycle
matthewhall115 0:4345759be364 28 wait(6); //spins for 6 seconds
matthewhall115 0:4345759be364 29 }//end if
matthewhall115 0:4345759be364 30
matthewhall115 0:4345759be364 31 if (c == 'r') { //if the character 'r' is pressed
matthewhall115 0:4345759be364 32 led != led;
matthewhall115 0:4345759be364 33 printf("Enter Duty Cycle in -0.XX form to move right: \n\n"); //asking for user input
matthewhall115 0:4345759be364 34 scanf("%f", &dc); //storing user input
matthewhall115 0:4345759be364 35 puts("Moving right!\n\n");
matthewhall115 0:4345759be364 36 m.speed(dc); //moving the motor at the user's desired duty cycle
matthewhall115 0:4345759be364 37 wait(6); //spins for 6 seconds
matthewhall115 0:4345759be364 38 }//end if
matthewhall115 0:4345759be364 39
matthewhall115 0:4345759be364 40 } //end while
matthewhall115 0:4345759be364 41
matthewhall115 0:4345759be364 42 } //end main(1)