My apology for troubling you again. I tried to use the library and add altitude check and the servo code to it. However, I got an error message when I compiled the codes. I hope you can assist me on this. Below is the code and also the error message.
/////////////////////////////////////////////////////////////////////////////////
// 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 (bmp280.getAltitude(1013.23f) > -14.45) {
Myservo1.write(90);
Myservo2.write(90);
Myservo3.write(90);
}
else{
Myservo1.write(0);
Myservo2.write(0);
Myservo3.write(0);
}
}
Arduino: 1.8.16 (Mac OS X), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
/var/folders/jz/z7fc17697dzbdj3cmb_sjd9c0000gn/T/arduino_modified_sketch_764643/BMP280_I2C_Normal.ino: In function 'void loop()':
BMP280_I2C_Normal:48:34: error: cannot bind non-const lvalue reference of type 'float&' to an rvalue of type 'float'
if (bmp280.getAltitude(1013.23f) > -14.45) {
^
In file included from /var/folders/jz/z7fc17697dzbdj3cmb_sjd9c0000gn/T/arduino_modified_sketch_764643/BMP280_I2C_Normal.ino:5:0:
/Users/karenma/Documents/Arduino/libraries/BMP280_DEV/BMP280_DEV.h:158:11: note: initializing argument 1 of 'uint8_t BMP280_DEV::getAltitude(float&)'
uint8_t getAltitude(float &altitude); // Get an altitude measurement
^~~~~~~~~~~
exit status 1
cannot bind non-const lvalue reference of type 'float&' to an rvalue of type 'float'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.