Project

Dependencies:   Motor Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
corwinstites
Date:
Thu Oct 25 15:03:53 2018 +0000
Parent:
4:b3bd945920cd
Commit message:
updated

Changed in this revision

project.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/project.cpp	Wed Oct 24 19:57:52 2018 +0000
+++ b/project.cpp	Thu Oct 25 15:03:53 2018 +0000
@@ -5,7 +5,6 @@
 void mov1(void); // Defining functions
 void mov2(void);
 void mov3(void);
-void lit(void);
 
 Servo uparm(p21); // Assigns pins to servo
 Servo lowarm(p22);
@@ -17,6 +16,7 @@
 DigitalIn s4(p17);
 DigitalOut lights[5] = {p5,p6,p7,p8,p11}; // Assigns LED pens
 
+int a,b,c,d;
 
 int main() 
 {
@@ -26,7 +26,6 @@
     uparm = .5; // halfway points 
     lowarm = .5;
 
-    int a,b,c,d;
 
 while(1){ // continuous while statement 
     
@@ -39,6 +38,7 @@
         table.speed(0);
         uparm = .5;
         lowarm = .5;
+        lights[0]=1;
         lights[1]=0;
         lights[2]=0;
         lights[3]=0;
@@ -47,29 +47,50 @@
     
     else if (a==1 && b==0 && c==0 && d==0)
     { // if only switch one is on, lights are on and table spins. 
-        table.speed(.25);
-        lit();
+        table.speed(.4);
+        lights[0]=1;
+        lights[1]=1;
+        lights[2]=0;
+        lights[3]=0;
+        lights[4]=0;
+        printf("Turning");
     } // 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(.25);
+        table.speed(.4);
+        lights[0]=1;
+        lights[1]=1;
+        lights[2]=1;
+        lights[3]=0;
+        lights[4]=0;
         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(.25);
+        table.speed(.4);
+        lights[0]=1;
+        lights[1]=1;
+        lights[2]=1;
+        lights[3]=1;
+        lights[4]=0;
         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(.25);
+        table.speed(.4);
+        lights[0]=1;
+        lights[1]=1;
+        lights[2]=1;
+        lights[3]=1;
+        lights[4]=1;
         mov3();
-        lit();
+       
     } // end if 
     else{
         table.speed(0);
         uparm = .5;
         lowarm = .5;
+        lights[0]=1;
         lights[1]=0;
         lights[2]=0;
         lights[3]=0;
@@ -79,39 +100,30 @@
 }// 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){
+    while(a==1 && b==1 && c==0 && d==0){
+    a = base.read(); // reads in switch values 
+    b = s2.read(); 
+    c = s3.read();
+    d = s4.read();
     for (i=0; i<40; i++){
-    uparm = .5 + i*0.00833;
-    wait(.075);
+    uparm = .5 + i*0.0041666;
+    wait(.038);
     }
-    uparm = 0.833;
+    uparm = 0.66667;
     for (j=0; j<40; j++){
-    uparm = 0.833-j*0.00833;
-    wait(.075);
+    uparm = 0.66667-j*0.0041666;
+    wait(.038);
     printf("Movement 1 \n\r");
     }
     }
-    }
+}
     
 
 void mov2(void){
@@ -119,41 +131,49 @@
     int j;
     lowarm = .5;
     uparm = .5;
-    while(1){
+    while(a==1 && b==0 && c==1 && d==0){
+    a = base.read(); // reads in switch values 
+    b = s2.read(); 
+    c = s3.read();
+    d = s4.read();
     for (i=0; i<40; i++){
-    uparm = .5 + i*0.00833;
-    lowarm = .5 + i*0.00833;
-    wait(.075);
+    uparm = .5 + i*0.00208333;
+    lowarm = .5 + i*0.0041666;
+    wait(.038);
     }
-    uparm = 0.833;
-    lowarm= 0.833;
+    uparm = 0.58333;
+    lowarm= 0.66667;
     for (j=0; j<40; j++){
-    uparm = 0.833-j*0.00833;
-    lowarm = 0.833-j*0.00833;
-    wait(.075);
+    uparm = 0.58333-j*0.00208333;
+    lowarm = 0.66667-j*0.0041666;
+    wait(.038);
     printf("Movement 2 \n\r");
     }
     }
-    }
+}
 
 void mov3(void) {
     int i;
     int j;
     lowarm = .5;
-    uparm = .833;
-    while(1){
+    uparm = 0.66667;
+    while(a==1 && b==0 && c==0 && d==1){
+    a = base.read(); // reads in switch values 
+    b = s2.read(); 
+    c = s3.read();
+    d = s4.read();
     for (i=0; i<40; i++){
-    uparm = 0.833 - i*0.00833;
-    lowarm = .5 + i*0.00833;
-    wait(.075);
+    uparm = 0.66667 - i*0.0041666;
+    lowarm = .5 + i*0.0041666;
+    wait(.038);
     }
     uparm = 0.5;
-    lowarm= .833;
+    lowarm= 0.66667;
     for (j=0; j<40; j++){
-    uparm = .5 + j*0.00833;
-    lowarm = 0.833-j*0.00833;
-    wait(.075);
+    uparm = .5 + j*0.0041666;
+    lowarm = 0.66667-j*0.0041666;
+    wait(.038);
     printf("Movement 3 \n\r");
     }
     }
-    }
+}