Fa2018-es200-1121-project2-herndon-toss / Mbed 2 deprecated Project2

Dependencies:   Motor Servo mbed mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stdio.h"
00003 #include "Motor.h"
00004 #include "math.h"
00005 #include "Servo.h"
00006 #include "rtos.h"  //need to add this library for multiple functions running at once
00007 
00008 
00009 
00010 int s1, s3, s4, i;
00011 float x;
00012 float y;
00013 AnalogIn turn(p15);  //turn dial to adjust servo for horizontal angle of arm SWITCH 2
00014 DigitalIn swtch1(p25); //moves herndon monument on turn table continuously while switch is on
00015 DigitalIn swtch3(p18); //releases the cover when switch 3 is turned on
00016 DigitalIn swtch4(p19); //retracts arm back to starting position to try again
00017 Motor m(p26, p30, p29); //launches the cover
00018 //DigitalIn sw1 (p16) ;     not sure why this is here - maybe broken pin
00019 
00020 Servo back(p21); //servo to move monument on turn table
00021 Servo angle(p22); //servo to adjust horizontal angle of arm
00022 
00023 int main() {
00024     /*
00025     s1 = swtch1.read(); //read state of switch 1
00026     angle.calibrate(0.0009, 90.0);
00027     back.calibrate(0.0009, 90.0); //calculate's servos timing by setting pulse width and range
00028     
00029     while (s1 == 1)  //moves herndon monument continuously on turn table
00030     {
00031        for (i = 0; i < 18; i++) //moves monument 180 degrees one way
00032        {
00033        back = 0;
00034        back = (0.0 + (i/18.0));
00035      s1 = swtch1.read(); //read state of switch 1
00036       }//end of for loop
00037       
00038       i=0;
00039       
00040       for (i = 0; i < 18; i++)  //moves monument back and another 180 degress the opposite way
00041        {
00042        back = 1;
00043        back = (1.0 - (i/18.0));
00044      s1 = swtch1.read(); //read state of switch 1
00045       }//end of for loop
00046       
00047       i = 0;
00048       
00049       }//end of while loop
00050       
00051       
00052       
00053 //Adjust horiztonal angle with switch 2/dial    
00054        while(1) {
00055     y = turn.read(); //reads the state of the dial the user changes
00056         printf("The dial is at %f\n", x);
00057     angle.write(y);  //makes the servo turn according to the dial
00058         printf("The servo is at %f\n", x);
00059    
00060 } //end of while loop
00061 
00062 */
00063 while(1) {
00064     
00065     swtch3.read(); //read state of switch 3 (launch the cover)
00066     if (swtch3==1) {
00067         while(1) {
00068             printf("motor on");
00069             m.speed(1.0);
00070             wait (.4);
00071             printf("motor off");
00072             m.speed(0.0);
00073             wait (1);
00074             break;
00075         } //end of while
00076         } //end of if
00077         
00078         
00079         
00080         
00081     s4 = swtch4.read(); //read state of switch 4 (retract arm to try again)
00082     if (s4 == 1){
00083         while(1) {
00084            printf("reversed");
00085             m.speed(-.25);
00086             wait(.6);
00087             printf("motor off");
00088             m.speed(0);
00089             wait(1);
00090             break;
00091         } //end of while
00092         } //end of if
00093         }//end of int main
00094 }