void SW_state(){
//0-boot mode
//1-test mode don't know
int p1=pressure[0]/100;
int p2=pressure[1]/100;
int p3=pressure[2]/100;
float a1=altitudes[0];
float a2=altitudes[1];
float a3=altitudes[2];
// if (p1==p2 && p2==p3 && a1==a2 && a2==a3)
if (a1<=5.0 && a2<=5.0 && a3<=5.0){
SWstate=2;//launch pad
// s.write(180);
}
else if (p2<p1 && p3<p2 && a2>a1 && a3>a2 && a1>5.0 && a2>5.0 && a3>5.0) {
SWstate=3; //Ascent
if (a1>800.0 && a1<=900.0 && a3<a1 && p3>p1 ){
//camera should start recording here
ON_camera();
SWstate=4; //Deployment
}
}
else if (p2>p1 && p3>p2 && a2<a1 && a3<a2 && a1<800.0 && a2<800.0 && a3<800.0 ){
SWstate=5; //Descent
if (a3>=500.0){
//ON_camera();
s.write(180); //servo turns to deploy second parachute
SWstate=6; //Aerobreak Release
// if (p1==p2 && p2==p3 && a1==a2 && a2==a3)
if (a1<5.0 && a2<5.0 && a3<5.0){
SWstate=7;//Impact
OFF_camera(); //camera stops recording here
//buzzer should switch on here
}
}
}
packet+=String(SWstate);
packet+=">\r";
}