coding for the sub

Dependencies:   mbed Motor Servo

Revision:
8:ef878ee3f536
Parent:
7:2a445f634f19
--- a/main.cpp	Tue Oct 16 12:00:48 2018 +0000
+++ b/main.cpp	Mon Oct 22 12:44:17 2018 +0000
@@ -7,52 +7,89 @@
 */
 
 
-DigitalIn sw(p20);
-Motor m(p26,p30,p29);
+DigitalIn prop(p16); //switch to turn on the prop
+DigitalIn shoot(p17); //switch to fire the torpedo
+DigitalIn planes(p18); //switch to tilt the fairwater planes
+DigitalIn lights(p19); //switch to turn on the running lights
+int screw;
+int fire;
+int fw;
+int running;
+DigitalOut green(p6); //green light
+DigitalOut red(p7); //red light
+Motor m(p26,p30,p29); //motor variable
+Servo torpedo(p21); //torpedo servo
+Servo tilt(p22); //planes servo
 
-int main(){
-    while(1){
-    sw.read();
-if (sw==1)
-{
-    printf("motor on");
-    m.speed(0.5);
-}
-else{
-    printf("motor off");
-m.speed(0.0);
-}
-wait(0.1);
-}
-}
 
-DigitalIn sw2(p19);
-Servo t(p22);
-float pos = 0.0;
-int main(){
-    t.calibrate(0.0009, 90.0);
-    t = pos; 
-    while(1){
-    sw2.read();
-if (sw2.read()==1)
-{
-    printf("servo on");
-    for(int x=0; x<50; x++)
-    { t=x/100.0;
-    
-    
-    wait(0.10);
+int main(){  //main open
+  printf("ES200 1121 Project 2 Team 2\r\n");
+  printf("Submarines\r\n");
+
+
+   while(1) { //while open
+        printf("reading switch positions\r\n");
+       screw = prop.read();  //reads switch for prop
+       fire = shoot.read();  //reads switch for torpedo
+       fw = planes.read();  //reads switch for planes
+       running = lights.read();  //reads switch for lights
+       
+   if (screw ==1) { //switch 1 for prop to spin
+     printf("spin propulsor\r\n");
+     for (float s= 0.0; s < 1.0 ; s += 0.01) {  //for loop with variable 's' that spools up the prop motor
+       m.speed(s);  //speed output with variable 's'
+       wait(0.01); //very small wait time in for loop to spool up quickly
     }
-    for(int x=50;x>0;x--){
-        t = x/100.0;
-        
-        wait(0.10);
+    }
+    else if (screw==0){
+    m.speed(0.0);
     }
     
-}
-else{
-    printf("servo off");
-}
-wait(0.1);
-}
-}
\ No newline at end of file
+   if (fire == 1) { //switch 2 for torpeo firing
+     printf("torpedo\r\n");
+     }
+/*       while(1) {
+    torpedo = 0.01; //start position inside body of sub
+    wait(1.5);  //wait
+    torpedo = 0.5;  //fire 
+    position outside of sub
+    wait (1.0);  //wait
+       }
+       }
+       else if (fire==0) {
+           torpedo = 0.01;
+           }*/
+   
+    if (fw == 1) { //switch 3 for planes
+      printf("planes\r\n");
+      tilt = 0.2;
+      wait(0.2);
+      tilt = 0.7;
+      wait(0.2); 
+    }
+    else {
+        printf("no planes\r\n");
+        tilt = 0.0; 
+        }
+    /*while(1) {
+    tilt = 0.2; //initial position
+    wait(0.7);  //wait
+    tilt = 0.7;  //tilted position
+    wait(0.7);  //wait
+} //while close
+} //else if close
+    else if (fw==0) {
+        tilt = 0.2;
+        }
+   */
+   
+   
+ /* if (running== 1) { //switch 4 for lights to turn on
+   green = 1;
+   red = 1;
+   }
+   */
+  } //while close
+  } //main close
+
+   
\ No newline at end of file