Start of project 2

Dependencies:   Motor Servo mbed mbed-rtos

main.cpp

Committer:
m215676
Date:
2018-10-16
Revision:
5:27689dbb0c6e
Parent:
4:a3e95c9d56d5
Child:
6:3dc339508843

File content as of revision 5:27689dbb0c6e:

#include "mbed.h"
#include "stdio.h"
#include "Motor.h"
#include "math.h"
#include "Servo.h"

int s1, s3, s4, i;
float x;
float y;
AnalogIn turn(p15);  //turn dial to adjust servo for horizontal angle of arm
DigitalIn swtch1(p19);
DigitalIn swtch3(p20);
DigitalIn swtch4(p21);
Motor m(p26, p30, p29);
DigitalIn sw1 (p16) ;

Servo back(p21); //servo to move monument on turn table
Servo angle(p22); //servo to adjust horizontal angle of arm

int main() {
    s1 = swtch1.read(); //read state of switch 1
    angle.calibrate(0.0009, 90.0);
    back.calibrate(0.0009, 90.0); //calculate's servos timing by setting pulse width and range
    
    while (s1 == 1)
    {
       for (i = 0; i < 18; i++) //moves monument 180 degrees one way
       {
       back = 0;
       back = (0.0 + (i/18.0));
     s1 = swtch1.read(); //read state of switch 1
      }//end of for loop
      
      for (i = 0; i < 35; i++)  //moves monument back and another 180 degress the opposite way
       {
       back = 1;
       back = (1.0 - (i/18.0));
     s1 = swtch1.read(); //read state of switch 1
      }//end of for loop
      
      }//end of while loop
      
      
      
//Adjust horiztonal angle with switch 2/dial    
       while(1) {
    y = turn.read(); //reads the state of the dial the user changes
        printf("The dial is at %f\n", x);
    angle.write(y);  //makes the servo turn according to the dial
        printf("The servo is at %f\n", x);
   
} //end of while loop


    
    sw3.read(); //read state of switch 3 (launch the cover)
    if (sw3==1) {
        while(1) {
            m.speed(1);
            wait (.15);
            m.speed(0);
            wait (1);
            break;
        } //end of while
        } //end of if
        
        
        
        
    sw4.read(); //read state of switch 4 (retract arm to try again)
    if (s4 == 1){
        while(1) {
            m.speed(-.25);
            wait(.6);
            m.speed(0);
            wait(1);
            break;
        } //end of while
        } //end of if
    } //end of int main