If loop during rest of loop

I need an if() statement to run continuously, without stopping the rest of the loop. How can I do this?

There can be no brakes... I have a bunch of delays in the rest of the program, but I need to keep both of these individual program parts running at the same time.

if(x is true)
set a flag;

if (flag)
{
do one part
}

Reset the flag when complete.

DON'T use delays if you need something time critical!!!!!!!!!!!!!!!!!

Well it's obvious that I don't use delays with time-critical information, but the delays are only for sending info to the groundstation. I can't do that every ms hahaha I do that every 2 sec

For the resto of your response, you say that I flag something, but imagine: the flag is false, so it's working on that part of the program. Halfway this process my flag turns false, does it then stop what it's doing? Cause I assume it goes on finishing that loop (Which includes delays)

How about posting your sketch so that we can see what you are doing ?

Get rid of the delays and use a millis() based approach instead.

#include <Servo.h>
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

bool maxheight = false;
bool deploy = false;
float servoAltitude = 0;

Servo servo;

#define BME_SCK 15
#define BME_MISO 14
#define BME_MOSI 16
#define BME_CS 3

#define SEALEVELPRESSURE_HPA (1024.67) // Meet de druk op de grond!

Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);

void setup() {

  Serial.begin(9600);
  mySerial.begin(9600);
  
// BME680

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }
  
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150);
  delay(5000);

// GPS

  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);

// Servo Motor

delay(200);
servo.attach(6);
delay(200);
servo.write(180);
delay(200);
servo.detach();
delay(200);

}

uint32_t timer = millis();

void loop() {

// Parsing

char c = GPS.read();
  if ((c))
  if (GPS.newNMEAreceived()) {
  if (!GPS.parse(GPS.lastNMEA()))
      return;
  }

  if (millis() - timer > 2000) {
    timer = millis();
    
// GPS

    if (GPS.fix) {
      Serial.print("\n");          
      Serial.print("Location:");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", ");
      Serial.println(GPS.longitudeDegrees, 4);
      mySerial.print("\n");          
      mySerial.print("Location:");
      mySerial.print(GPS.latitudeDegrees, 4);
      mySerial.print(", ");
      mySerial.println(GPS.longitudeDegrees, 4);
    }

// BME680

      Serial.print("\n");
      Serial.print("Temperature = ");
      Serial.print(bme.temperature);
      Serial.println(" *C");
      mySerial.print("\n");
      mySerial.print("Temperature = ");
      mySerial.print(bme.temperature);
      mySerial.println(" *C");
    
      Serial.print("Pressure = ");
      Serial.print(bme.pressure / 100.0);
      Serial.println(" hPa");
      mySerial.print("Pressure = ");
      mySerial.print(bme.pressure / 100.0);
      mySerial.println(" hPa");
      
      Serial.print("Humidity = ");
      Serial.print(bme.humidity);
      Serial.println(" %");
      mySerial.print("Humidity = ");
      mySerial.print(bme.humidity);
      mySerial.println(" %");
      
      Serial.print("Gas = ");
      Serial.print(bme.gas_resistance / 1000.0);
      Serial.println(" KOhms");
      mySerial.print("Gas = ");
      mySerial.print(bme.gas_resistance / 1000.0);
      mySerial.println(" KOhms");
    
      Serial.print("Approx. Altitude = ");
      Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      Serial.println(" m");
      mySerial.print("Approx. Altitude = ");
      mySerial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      mySerial.println(" m");
  }
  
// Servo Motor

  servoAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  
  // Servo Motor: Max Height Initialization
  
if (servoAltitude >= 1) { mySerial.println("Above 1 m"); maxheight = true; }

  // Servo Motor: Deployment
  
    if (maxheight == true and servoAltitude <= 0.5)
    {
        mySerial.println("Deploying at height: "); mySerial.print(servoAltitude);
        
        delay(100);
        servo.attach(6);

        delay(100);
        servo.write(90);
        delay(700);
        servo.detach();
        delay(100);
        
        maxheight = !maxheight;
    }
}

I need the servo to rotate "EXACTLY" when the altitude drops below 0.5. what it does now, is finishing the first part of the loop, before checking to see if the altitude has drops. This leads to a maximum of 2 second delay. This would mean the parachute would deploy 36 meters too low

but the delays are only for sending info to the groundstation. I can't do that every ms hahaha I do that every 2 sec

I see no need for a delay to do that!

/*
 * Do stuff every 2 seconds
 */
unsigned long lastTimeRun = 0;
const long interval = 2000;

void setup()
{
 // do setup stuff here
}

void loop()
{
unsigned long MillisNow = millis();

  if (MillisNow - lastTimeRun >= interval)
  {
    //Do stuff here
    lastTimeRun = MillisNow;
  }
}

Oh, i'm stupid. I had one unnesessary delay. let me try something...

  if (millis() - timer > 2000) {
    timer += 2000;

.

Unless you think all that code take close-to zero time.

#include <Servo.h>
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

bool maxheight = false;
int mhact = 1;
bool deploy = false;
float servoAltitude = 0;

Servo servo;

#define BME_SCK 15
#define BME_MISO 14
#define BME_MOSI 16
#define BME_CS 3

#define SEALEVELPRESSURE_HPA (1025.06) // Meet de druk op de grond!

Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);

void setup() {

  Serial.begin(9600);
  mySerial.begin(9600);
  
// BME680

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }
  
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150);
  delay(5000);

// GPS

  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);

// Servo Motor

delay(200);
servo.attach(6);
delay(200);
servo.write(180);
delay(200);
servo.detach();
delay(200);

}

uint32_t timer = millis();

void loop() {

// Parsing

char c = GPS.read();
  if ((c))
  if (GPS.newNMEAreceived()) {
  if (!GPS.parse(GPS.lastNMEA()))
      return;
  }

  if (millis() - timer > 2000) {
    timer = millis();
    
// GPS

    if (GPS.fix) {
      Serial.print("\n");          
      Serial.print("Location:");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", ");
      Serial.println(GPS.longitudeDegrees, 4);
      mySerial.print("\n");          
      mySerial.print("Location:");
      mySerial.print(GPS.latitudeDegrees, 4);
      mySerial.print(", ");
      mySerial.println(GPS.longitudeDegrees, 4);
    }

// BME680

      Serial.print("\n");
      Serial.print("Temperature = ");
      Serial.print(bme.temperature);
      Serial.println(" *C");
      mySerial.print("\n");
      mySerial.print("Temperature = ");
      mySerial.print(bme.temperature);
      mySerial.println(" *C");
    
      Serial.print("Pressure = ");
      Serial.print(bme.pressure / 100.0);
      Serial.println(" hPa");
      mySerial.print("Pressure = ");
      mySerial.print(bme.pressure / 100.0);
      mySerial.println(" hPa");
      
      Serial.print("Humidity = ");
      Serial.print(bme.humidity);
      Serial.println(" %");
      mySerial.print("Humidity = ");
      mySerial.print(bme.humidity);
      mySerial.println(" %");
      
      Serial.print("Gas = ");
      Serial.print(bme.gas_resistance / 1000.0);
      Serial.println(" KOhms");
      mySerial.print("Gas = ");
      mySerial.print(bme.gas_resistance / 1000.0);
      mySerial.println(" KOhms");
    
      Serial.print("Approx. Altitude = ");
      Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      Serial.println(" m");
      mySerial.print("Approx. Altitude = ");
      mySerial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      mySerial.println(" m");
  }
  
// Servo Motor

  servoAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  
  // Servo Motor: Max Height Initialization
  
if (servoAltitude >= 1 and mhact == 1)
{ mySerial.println("Above 1 m"); Serial.println("Above 1 m"); 
  maxheight = true; mhact = mhact-1; }

  // Servo Motor: Deployment
  
    if (maxheight == true and servoAltitude <= 0.5)
    {   mySerial.print("Deploying at height: "); mySerial.println(servoAltitude);
        Serial.print("Deploying at height: "); Serial.println(servoAltitude);
        
        delay(100);
        servo.attach(6);

        delay(100);
        servo.write(90);
        delay(700);
        servo.detach();
        delay(100);
        
        maxheight = !maxheight;
    }
}

This is my code now, however it's still not rotating at the moment I want it to. It rotates when the last packet has been sent. Can someone show me what to change?

If you factored your code into functions, or used the auto format tool, (or both) you would see instantly where your problem is.

Uhhhm how does that work?

It cuts out all the visual noise, and allows you to concentrate on structure.

#include <Servo.h>
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

bool maxheight = false;
int mhact = 1;
bool deploy = false;
float servoAltitude = 0;

Servo servo;

#define BME_SCK 15
#define BME_MISO 14
#define BME_MOSI 16
#define BME_CS 3

#define SEALEVELPRESSURE_HPA (1025.06) // Meet de druk op de grond!

Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);

void setup() {

  Serial.begin(9600);
  mySerial.begin(9600);

  // BME680

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }

  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150);
  delay(5000);

  // GPS

  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);

  // Servo Motor

  delay(200);
  servo.attach(6);
  delay(200);
  servo.write(180);
  delay(200);
  servo.detach();
  delay(200);

}

uint32_t timer = millis();

void loop() {

  // Parsing

  char c = GPS.read();
  if ((c))
    if (GPS.newNMEAreceived()) {
      if (!GPS.parse(GPS.lastNMEA()))
        return;
    }

  if (millis() - timer > 2000) {
    timer = millis();

    // GPS

    if (GPS.fix) {
      Serial.print("\n");
      Serial.print("Location:");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", ");
      Serial.println(GPS.longitudeDegrees, 4);
      mySerial.print("\n");
      mySerial.print("Location:");
      mySerial.print(GPS.latitudeDegrees, 4);
      mySerial.print(", ");
      mySerial.println(GPS.longitudeDegrees, 4);
    }

    // BME680

    Serial.print("\n");
    Serial.print("Temperature = ");
    Serial.print(bme.temperature);
    Serial.println(" *C");
    mySerial.print("\n");
    mySerial.print("Temperature = ");
    mySerial.print(bme.temperature);
    mySerial.println(" *C");

    Serial.print("Pressure = ");
    Serial.print(bme.pressure / 100.0);
    Serial.println(" hPa");
    mySerial.print("Pressure = ");
    mySerial.print(bme.pressure / 100.0);
    mySerial.println(" hPa");

    Serial.print("Humidity = ");
    Serial.print(bme.humidity);
    Serial.println(" %");
    mySerial.print("Humidity = ");
    mySerial.print(bme.humidity);
    mySerial.println(" %");

    Serial.print("Gas = ");
    Serial.print(bme.gas_resistance / 1000.0);
    Serial.println(" KOhms");
    mySerial.print("Gas = ");
    mySerial.print(bme.gas_resistance / 1000.0);
    mySerial.println(" KOhms");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");
    mySerial.print("Approx. Altitude = ");
    mySerial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    mySerial.println(" m");
  }

  // Servo Motor

  servoAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

  // Servo Motor: Max Height Initialization

  if (servoAltitude >= 1 and mhact == 1)
  { mySerial.println("Above 1 m"); Serial.println("Above 1 m");
    maxheight = true; mhact = mhact - 1;
  }

  // Servo Motor: Deployment

  if (maxheight == true and servoAltitude <= 0.5)
  { mySerial.print("Deploying at height: "); mySerial.println(servoAltitude);
    Serial.print("Deploying at height: "); Serial.println(servoAltitude);

    delay(100);
    servo.attach(6);

    delay(100);
    servo.write(90);
    delay(700);
    servo.detach();
    delay(100);

    maxheight = !maxheight;
  }
}

This is what it looks like formatted. Can you help me figure out how to get the servo to turn when it gets below 0.5 m? It now only turns after having finished sending the last packet. I don't want it to send that packet though, I want it to go straight to where it rotates.

When I said factoring reduces the visual noise (in this, and your previous thread) I really meant it.

Can you see that this

Serial.print("Gas = ");
    Serial.print(bme.gas_resistance / 1000.0);
    Serial.println(" KOhms");

looks an awful lot like this

    mySerial.print("Gas = ");
    mySerial.print(bme.gas_resistance / 1000.0);
    mySerial.println(" KOhms");

?

Noise. Distracting.

Yeah but I can't just leave that out, I need to show it on my Serial Monitor when I'm not sending the info and I need to show it on the serial monitor I am sending to

#include <Servo.h>
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

bool maxheight = false;
int mhact = 1;
bool deploy = false;
float servoAltitude = 0;

Servo servo;

#define BME_SCK 15
#define BME_MISO 14
#define BME_MOSI 16
#define BME_CS 3

#define SEALEVELPRESSURE_HPA (1025.06) // Meet de druk op de grond!

Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);

void setup() {

  Serial.begin(9600);
  mySerial.begin(9600);

  // BME680

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }

  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150);
  delay(5000);

  // GPS

  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);

  // Servo Motor

  delay(200);
  servo.attach(6);
  delay(200);
  servo.write(180);
  delay(200);
  servo.detach();
  delay(200);

}

uint32_t timer = millis();

void loop() {

  // Parsing

  char c = GPS.read();
  if ((c))
    if (GPS.newNMEAreceived()) {
      if (!GPS.parse(GPS.lastNMEA()))
        return;
    }

  if (millis() - timer > 2000) {
    timer = millis();

    // GPS

    if (GPS.fix) {
      mySerial.print("\n");
      mySerial.print("Location:");
      mySerial.print(GPS.latitudeDegrees, 4);
      mySerial.print(", ");
      mySerial.println(GPS.longitudeDegrees, 4);
    }

    // BME680

    mySerial.print("Temperature = ");
    mySerial.print(bme.temperature);
    mySerial.println(" *C");

    mySerial.print("Pressure = ");
    mySerial.print(bme.pressure / 100.0);
    mySerial.println(" hPa");

    mySerial.print("Humidity = ");
    mySerial.print(bme.humidity);
    mySerial.println(" %");

    mySerial.print("Gas = ");
    mySerial.print(bme.gas_resistance / 1000.0);
    mySerial.println(" KOhms");

    mySerial.print("Approx. Altitude = ");
    mySerial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    mySerial.println(" m");
  }

  // Servo Motor

  servoAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

  // Servo Motor: Max Height Initialization

  if (servoAltitude >= 1 and mhact == 1)
  { mySerial.println("Above 1 m"); Serial.println("Above 1 m");
    maxheight = true; mhact = mhact - 1;
  }

  // Servo Motor: Deployment

  if (maxheight == true and servoAltitude <= 0.5)
  { mySerial.print("Deploying at height: "); mySerial.println(servoAltitude);

    delay(100);
    servo.attach(6);

    delay(100);
    servo.write(90);
    delay(700);
    servo.detach();
    delay(100);

    maxheight = !maxheight;
  }
}

Okay, here it is without the "noise" you were talking about, is this what you mean?

I never said anything about "leaving it out".
It's the same information (or, as I've said before, it should be the same information), going to different destinations, that's all.

Okay, thank you! How can I make it smaller? Is there a command to make the information go to 2 destinations at once?

Yes.
It's called a function.