float max value to compare to

I’m trying to write a code for a DemoSat project where a servo will be activated on decent around 500 m.
I’ve attached my current code below (minus the servo stuff and using pressure since that’s easier to manipulate that than altitude) but this is the general idea;

if (current_altitude>max_altitude){ //going up
float max_altitude = current altitude} //recording current alt as new max
if (current_altitude<500m and max_altitude>10000 m){ //Payload has come back to 500m after reaching 10000 m
activate servo}

Any suggestions?

max_alt_wip.ino (1.29 KB)

Raxius:
Any suggestions?

Yes.

  static float max_altitude = 0.0;
  if (current_altitude>max_altitude)   //going up
    max_altitude = current altitude;   //recording current alt as new max
  if (current_altitude < 500m and max_altitude >10000) {   
    // Payload has come back to 500m after reaching 10000 m activate servo}
}

You had max_altitude declared inside the if-statement so the new value of max_altitude would not be seen outside the if-statement

Yeah that works! thanks! I knew it had to be something simple.