void SW_state(){
//0-boot mode
//1-test mode don't know
if (cnt-4<=0){
SWstate=0;
packet+=String(SWstate);
packet+="\r";
}
else{
int p1=bmp.readPressure();
int p2=bmp.readPressure();
int p3=bmp.readPressure();
int a1=bmp.readAltitude(1013.25)-calibration;
int a2=bmp.readAltitude(1013.25)-calibration;
int a3=bmp.readAltitude(1013.25)-calibration;
if (p1%10==p2%10 && p2%10==p3%10 && a1==a2 && a2==a3){
SWstate=2; //launch pad
}
else if (p2%10<p1%10 && p3%10<p2%10 && a2>a1 && a3>a2){
SWstate=3; //Ascent
if (a1>800 && a1<=900 && a3<a1 && p3%10>p1%10 ){
//camera should start recording here
SWstate=4; //Deployment
}
}
else if (p2%10>p1%10 && p3%10>p2%10 && a2<a1 && a3<a2 ){
SWstate=5; //Descent
if (a3>=500){
s.write(180); //servo turns to deploy second parachute
SWstate=6; //Aerobreak Release
if (p1%10==p2%10 && p2%10==p3%10 && a1==a2 && a2==a3){
SWstate=7; //Impact
//buzzer should switch on here
}
}
}
packet+=String(SWstate);
packet+=">\r";
}
}