alt
This commit is contained in:
parent
60bb88f257
commit
1b188eed2f
|
|
@ -282,6 +282,18 @@ float Adafruit_BME280::readPressure(void) {
|
||||||
return (float)p/256;
|
return (float)p/256;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Adafruit_BME280::readAltitude(float seaLevelhPa) {
|
||||||
|
float altitude;
|
||||||
|
|
||||||
|
float pressure = readPressure(); // in Si units for Pascal
|
||||||
|
pressure /= 100;
|
||||||
|
|
||||||
|
altitude = 44330 * (1.0 - pow(pressure / seaLevelhPa, 0.1903));
|
||||||
|
|
||||||
|
return altitude;
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,8 +141,7 @@ class Adafruit_BME280
|
||||||
float readPressure(void);
|
float readPressure(void);
|
||||||
float readHumidity(void);
|
float readHumidity(void);
|
||||||
|
|
||||||
// float pressureToAltitude(float seaLevel, float atmospheric, float temp);
|
float readAltitude(float seaLevelhPa = 1013.25);
|
||||||
// float seaLevelForAltitude(float altitude, float atmospheric, float temp);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,15 @@ void loop() {
|
||||||
Serial.print("Pressure = ");
|
Serial.print("Pressure = ");
|
||||||
Serial.print(bme.readPressure());
|
Serial.print(bme.readPressure());
|
||||||
Serial.println(" Pa");
|
Serial.println(" Pa");
|
||||||
|
|
||||||
|
Serial.print("Approx altitude = ");
|
||||||
|
Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
|
||||||
|
Serial.println(" m");
|
||||||
|
|
||||||
Serial.print("Humidity = ");
|
Serial.print("Humidity = ");
|
||||||
Serial.print(bme.readHumidity());
|
Serial.print(bme.readHumidity());
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
delay(500);
|
delay(2000);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue