Hi @mikami2020
I've tweaked your code, so that it should work with the BMP280_DEV library:
/////////////////////////////////////////////////////////////////////////////////
// BMP280_DEV - I2C Communications, Default Configuration, Normal Conversion
/////////////////////////////////////////////////////////////////////////////////
#include <Servo.h>
#include <BMP280_DEV.h> // Include the BMP280_DEV.h library
int pushButton = 2;
int servoPin1 = 9;
int servoPin2 = 10;
int servoPin3 = 11;
int greenLed = 13;
Servo Myservo1; //define servos
Servo Myservo2;
Servo Myservo3;
int servoPos=0;
float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables
BMP280_DEV bmp280; // Instantiate (create) a BMP280_DEV object and set-up for I2C operation (address 0x77)
void setup()
{
Serial.begin(115200); // Initialise the serial port
bmp280.begin(); // Default initialisation, place the BMP280 into SLEEP_MODE
//bmp280.setPresOversampling(OVERSAMPLING_X4); // Set the pressure oversampling to X4
//bmp280.setTempOversampling(OVERSAMPLING_X1); // Set the temperature oversampling to X1
//bmp280.setIIRFilter(IIR_FILTER_4); // Set the IIR filter to setting 4
bmp280.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds
bmp280.startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE
pinMode(greenLed,OUTPUT);
Myservo1.attach(servoPin1);
Myservo2.attach(servoPin2);
Myservo3.attach(servoPin3);
}
void loop()
{
digitalWrite(greenLed, HIGH);
if (bmp280.getMeasurements(temperature, pressure, altitude)) // Check if the measurement is complete
{
Serial.print(temperature); // Display the results
Serial.print(F("*C "));
Serial.print(pressure);
Serial.print(F("hPa "));
Serial.print(altitude);
Serial.println(F("m"));
if (altitude > -14.5)
{
Myservo1.write(90);
Myservo2.write(90);
Myservo3.write(90);
}
else
{
Myservo1.write(0);
Myservo2.write(0);
Myservo3.write(0);
}
}
}
This will cause the code to sample the barometer every 2 seconds without stopping in the loop(), in other words non-blocking.
The sample rate can be changed by amending the line in the setup() function:
bmp280.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds
It can be replaced by any of these intervals:
TIME_STANDBY_05MS
TIME_STANDBY_62MS
TIME_STANDBY_125MS
TIME_STANDBY_250MS
TIME_STANDBY_500MS
TIME_STANDBY_1000MS
TIME_STANDBY_2000MS
TIME_STANDBY_4000MS