CORE
/
Sample_BMP180
Sample for BMP180 (used by Nucleo-STMF303K8)
Diff: main.cpp
- Revision:
- 0:0ff20d8e9090
- Child:
- 1:b9ea35d93329
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 07 05:17:35 2016 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" +#include "math.h" +#include "BMP180.h" +#define p0 1013.25f//海面気圧 + +DigitalOut myled(LED1); +Serial pc(USBTX,USBRX); +BMP180 bmp(PB_7, PB_6); +Timer timer; + +float getAlt(float press, float temp); + +int main() { + float pressure,temperature,altitude; + float time; + bmp.Initialize(64,BMP180_OSS_ULTRA_LOW_POWER); + pc.printf("time, temperature ,pressure, altitude\r\n"); + timer.start(); + + while(1) { + bmp.ReadData(&temperature,&pressure); + altitude = getAlt(pressure,temperature); + time = timer.read(); + pc.printf("%f, %f, %f, %f \r\n",time, temperature, pressure, altitude); + myled =! myled; + wait(1); + } +} + +float getAlt(float press, float temp){ + return (pow((p0/press), (1.0f/5.257f))-1.0f)*(temp+273.15f)/0.0065f; +} \ No newline at end of file