coding for the sub

Dependencies:   mbed Motor Servo

main.cpp

Committer:
m212760
Date:
2018-10-22
Revision:
8:ef878ee3f536
Parent:
7:2a445f634f19

File content as of revision 8:ef878ee3f536:

#include "mbed.h"
#include "stdio.h"
#include "stdlib.h"
#include "Motor.h"
#include "Servo.h"
/* this is the code for the sub
*/


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(){  //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
    }
    }
    else if (screw==0){
    m.speed(0.0);
    }
    
   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