Start of project 2

Dependencies:   Motor Servo mbed mbed-rtos

main.cpp

Committer:
m215676
Date:
2018-10-22
Revision:
7:adcdd7556997
Parent:
6:3dc339508843

File content as of revision 7:adcdd7556997:

#include "mbed.h"
#include "stdio.h"
#include "Motor.h"
#include "math.h"
#include "Servo.h"
#include "rtos.h"  //need to add this library for multiple functions running at once



int s1, s3, s4, i;
float x;
float y;
AnalogIn turn(p15);  //turn dial to adjust servo for horizontal angle of arm SWITCH 2
DigitalIn swtch1(p25); //moves herndon monument on turn table continuously while switch is on
DigitalIn swtch3(p18); //releases the cover when switch 3 is turned on
DigitalIn swtch4(p19); //retracts arm back to starting position to try again
Motor m(p26, p30, p29); //launches the cover
//DigitalIn sw1 (p16) ;     not sure why this is here - maybe broken pin

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)  //moves herndon monument continuously on turn table
    {
       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
      
      i=0;
      
      for (i = 0; i < 18; 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
      
      i = 0;
      
      }//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

*/
while(1) {
    
    swtch3.read(); //read state of switch 3 (launch the cover)
    if (swtch3==1) {
        while(1) {
            printf("motor on");
            m.speed(1.0);
            wait (.4);
            printf("motor off");
            m.speed(0.0);
            wait (1);
            break;
        } //end of while
        } //end of if
        
        
        
        
    s4 = swtch4.read(); //read state of switch 4 (retract arm to try again)
    if (s4 == 1){
        while(1) {
           printf("reversed");
            m.speed(-.25);
            wait(.6);
            printf("motor off");
            m.speed(0);
            wait(1);
            break;
        } //end of while
        } //end of if
        }//end of int main
}