ggg

Dependencies:   Motor mbed

main.cpp

Committer:
matthewhall115
Date:
2018-03-09
Revision:
0:4345759be364

File content as of revision 0:4345759be364:

#include "mbed.h"
#include "Motor.h"  // program to drive DC motor
#define PI (3.14159)  //define PI to make life easy 

PwmOut led(LED2);     //define led
Motor m(p21,p22,p22); //define pins for MBED/TD340 communication

//Declare global variables for data handling
char c;  //declaring character 'c'
float dc; //float called dc, duty cycle

int main ()     //main function
{


    while(1) {
        led=0;          //LED off
        m.speed(0);     //motor is off
        c = getchar();   //get character inpput from user


        if (c == 'l') {     //if the character 'l' is pressed
            led != led;
            printf("Enter Duty Cycle in +0.XX form to move left: \n\n"); //asking for user input
            scanf("%f", &dc);   //storing user input
            puts("Moving left!\n\n");
            m.speed(dc);  //moving the motor at the user's desired duty cycle
            wait(6);  //spins for 6 seconds
        }//end if

        if (c == 'r') {        //if the character 'r' is pressed
            led != led;
            printf("Enter Duty Cycle in -0.XX form to move right: \n\n"); //asking for user input
            scanf("%f", &dc);   //storing user input
            puts("Moving right!\n\n"); 
            m.speed(dc);  //moving the motor at the user's desired duty cycle
            wait(6);  //spins for 6 seconds
        }//end if

    } //end while

} //end main(1)