Project

Dependencies:   Motor Servo mbed

Revision:
1:ed0f48d7be99
Parent:
0:17c1875334d9
Child:
2:460005c21162
--- a/project.cpp	Mon Oct 22 00:18:46 2018 +0000
+++ b/project.cpp	Wed Oct 24 01:29:53 2018 +0000
@@ -2,25 +2,159 @@
 #include "Servo.h"
 #include "Motor.h"
 
-Servo uparm(p21);
+void mov1(void); // Defining functions
+void mov2(void);
+void mov3(void);
+void lit(void);
+
+Servo uparm(p21); // Assigns pins to servo
 Servo lowarm(p22);
-Motor table(p26, p29, p30);
-DigitalIn s1(p20);
+Motor table(p26, p29, p30); // Assigns DC pins
+
+DigitalIn base(p20); // Assigns switch pins 
 DigitalIn s2(p19);
 DigitalIn s3(p18);
 DigitalIn s4(p17);
+DigitalOut lights[5] = {p21,p22,p23,p24,p25}; // Assigns LED pens
+
 
 int main() 
 {
-uparm.calibrate(0.0009,90);
-lowarm.calibrate(0.0009,90);
-while(1){
-printf("Enter");
-getchar();
-uparm = .8;
-lowarm= 1;
-getchar();
-uparm = .2;
-lowarm = 0;
-}
-}
+
+    uparm.calibrate(0.0009,90);// calibrates arm loaations
+    lowarm.calibrate(0.0009,90);
+    uparm = .5; // halfway points 
+    lowarm = .5;
+
+    int a,b,c,d;
+
+while(1){ // continuous while statement 
+    
+    a = base.read(); // reads in switch values 
+    b = s2.read(); 
+    c = s3.read();
+    d = s4.read();
+    
+    if (a==0) { // if switch one is off, entire program does not turn on and arms calibrate 
+        table.speed(0);
+        uparm = .5;
+        lowarm = .5;
+        lights[1]=0;
+        lights[2]=0;
+        lights[3]=0;
+        lights[4]=0;
+    } // end if
+    
+    else if (a==1 && b==0 && c==0 && d==0)
+    { // if only switch one is on, lights are on and table spins. 
+        table.speed(.2);
+        lit();
+    } // end if 
+   
+    else if (a==1 && b==1 && c==0 && d==0){ // if switches one and two are on, table spins, and movement 1 happens
+        table.speed(.2);
+        mov1();
+        lit();
+    } // end if
+    else if (a==1 && b==0 && c==1 && d==0){ // if switches one and three on, table spins, movement two happens
+        table.speed(.2);
+        mov2();
+        lit();
+    } // end if 
+    else if (a==1 && b==0 && c==0 && d==1){ // if switches one and three are on, table speens, movement three
+        table.speed(.2);
+        mov3();
+        lit();
+    } // end if 
+    else{
+        table.speed(0);
+        uparm = .5;
+        lowarm = .5;
+        lights[1]=0;
+        lights[2]=0;
+        lights[3]=0;
+        lights[4]=0;
+    } // end if
+        
+    
+        
+    
+}// end while
+} // end main
+
+ void lit(void){
+    int i;
+    while (1){
+    for (i=0; i<5; i++)
+    {
+        lights[i]=1; 
+        lights[i-1]=0;
+        wait(.5);             
+        if (i == 4) {
+            lights[4]=0;
+        }
+    }
+    }
+    }
+
+ void mov1(void){
+    int i;
+    int j;
+    lowarm = .5;
+    uparm = .5;
+    while(1){
+    for (i=0; i<40; i++){
+    uparm = .5 + i*0.00833;
+    wait(.075);
+    }
+    uparm = 0.833;
+    for (j=0; j<40; j++){
+    uparm = 0.833-j*0.00833;
+    wait(.075);
+    printf("ahh");
+    }
+    }
+    }
+    
+
+void mov2(void){
+    int i;
+    int j;
+    lowarm = .5;
+    uparm = .5;
+    while(1){
+    for (i=0; i<40; i++){
+    uparm = .5 + i*0.00833;
+    lowarm = .5 + i*0.00833;
+    wait(.075);
+    }
+    uparm = 0.833;
+    lowarm= 0.833;
+    for (j=0; j<40; j++){
+    uparm = 0.833-j*0.00833;
+    lowarm = 0.833-j*0.00833;
+    wait(.075);
+    }
+    }
+    }
+
+void mov3(void) {
+    int i;
+    int j;
+    lowarm = .5;
+    uparm = .833;
+    while(1){
+    for (i=0; i<40; i++){
+    uparm = 0.833 - i*0.00833;
+    lowarm = .5 + i*0.00833;
+    wait(.075);
+    }
+    uparm = 0.5;
+    lowarm= .833;
+    for (j=0; j<40; j++){
+    uparm = .5 + j*0.00833;
+    lowarm = 0.833-j*0.00833;
+    wait(.075);
+    }
+    }
+    }