Xiao nrf52840 Sense: BLE connection is lost during delay()

Hi PJ_GLasse
Thanks for the respons and the advide on using milli’s. However I still have the problem that is disconnec to the central if the pause is more than 20-30 sek. I have written an example and would appriciate any advice on how to keep the connection during the “pause”

#include "LSM6DS3.h"
#include "Wire.h"
#include <ArduinoBLE.h>  // Arduino BLE library

//Create a instance of class LSM6DS3
LSM6DS3 myIMU(I2C_MODE, 0x6A);  //I2C device address 0x6A
const char* UUID_serv = "75681d64-fd7e-40f7-874f-c6f2e7ec996c";

// UUids for accelerometer characteristics
const char* UUID_AccBLE = "75681d64-dd7e-40f7-874f-c6f2e7ec996c";

BLEService myService(UUID_serv);
BLEIntCharacteristic AccBLE(UUID_AccBLE, BLERead | BLENotify);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {

    pinMode(LEDB, OUTPUT);  // onboard led blue
    //Call .begin() to configure the IMUs
    if (myIMU.begin() != 0) {
      Serial.println("Device error");
    } else {
      Serial.println("Device OK!");
    }
    // init BLE
    if (!BLE.begin()) {
      Serial.println("BLE: failed");
    }
    Serial.println("BLE: ok");

    BLE.setAdvertisedService(myService);
    myService.addCharacteristic(AccBLE);
    BLE.addService(myService);
    AccBLE.writeValue(0);
    // start advertising
    BLE.advertise();
    Serial.println("Advertising started");
    Serial.println("Bluetooth device active, waiting for connections...");
  }
}
float accelerometerX;
unsigned long BreakPreviousMillis;

int x_time = 40000;
void loop() {
  BLEDevice central = BLE.central();
  if (central) {
    Serial.print("Connected to central: ");


    while (central.connected()) {
      accelerometerX = myIMU.readFloatAccelX();
      if (accelerometerX > 2) {
        BreakPreviousMillis = millis();
        while (millis() < BreakPreviousMillis + x_time) {
          Serial.println("pause");
        }
      }
      AccBLE.writeValue(accelerometerX);
    }

    digitalWrite(LEDB, HIGH);  // High == turning off the Led
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }
}