Threaded version of ES200 1121 Team Dolphin Club sub code.
main.cpp
- Committer:
- evangeli
- Date:
- 2018-10-22
- Revision:
- 0:cf9c71a62530
- Child:
- 2:c7591cd567c8
File content as of revision 0:cf9c71a62530:
/*
ES200 1121 Project 2 Dolphin Club
Run silent run deep.
MIDN 3/c Enger, Ewing, Hicks, Jordan
*/
#include "mbed.h" // DE transitioned this to mbed OS 5 to do multitasking and threads
#include "rtos.h"
#include "stdio.h"
#include "Motor.h"
#include "Servo.h"
// Global hardware objects
Serial pc(USBTX,USBRX); // for talking back to computer
// inputs
DigitalIn prop_sw(p16); //switch to turn on the prop
DigitalIn torpedo_sw(p17); //switch to fire the torpedo
DigitalIn planes_sw(p18); //switch to tilt the fairwater planes
DigitalIn lights_sw(p19); //switch to turn on the running lights
// outputs
DigitalOut green(p6); // external green LED
DigitalOut red(p7); // external red LED
Motor prop_motor(p26,p30,p29); //motor variable
Servo torpedo_servo(p21); //torpedo servo
Servo planes_servo(p22); //planes servo
// other indicators
DigitalOut heartbeat_led(LED1);
DigitalOut prop_led(LED2);
DigitalOut torpedo_led(LED3);
DigitalOut planes_led(LED4);
// do i need these???
int screw;
int fire;
int fw;
int running;
// threads
Thread prop_thread;
Thread torpedo_thread;
Thread planes_thread;
Thread lights_thread;
// callback function prototypes
void prop_callback(void);
void torpedo_callback(void);
void planes_callback(void);
void lights_callback(void);
int main(void){ //main open
pc.printf("ES200 1121 Project 2 Team 2 Dolphin Club\r\n");
pc.printf("Submarines go deeper.\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 (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
void prop_callback(void)
{
pc.printf("prop_thread standing by ready to answer bells on main engine\r\n");
while(1) {
if (prop_sw.read()) {
pc.printf("prop_thread all ahead flank\r\n");
prop_motor.speed(1.0);
} else {
pc.printf("prop_thread all stop\r\n");
prop_motor.speed(0.0);
}
} // while(1)
} // prop_callback()
void torpedo_callback(void)
{
//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;
}*/
}