This commit is contained in:
ladyada 2015-09-14 01:10:52 -04:00
parent 60bb88f257
commit 1b188eed2f
3 changed files with 19 additions and 4 deletions

View File

@ -282,6 +282,18 @@ float Adafruit_BME280::readPressure(void) {
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;
}
/**************************************************************************/
/*!

View File

@ -141,8 +141,7 @@ class Adafruit_BME280
float readPressure(void);
float readHumidity(void);
// float pressureToAltitude(float seaLevel, float atmospheric, float temp);
// float seaLevelForAltitude(float altitude, float atmospheric, float temp);
float readAltitude(float seaLevelhPa = 1013.25);
private:

View File

@ -47,11 +47,15 @@ void loop() {
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
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(bme.readHumidity());
Serial.println(" %");
Serial.println();
delay(500);
}
delay(2000);
}