気圧センサ(nucleo用)-sammple code

Dependencies:   mbed LPS25HB_I2C

main.cpp

Committer:
kosukesuzuki
Date:
2022-08-09
Revision:
1:e8b472ec4bb2
Parent:
0:03ee8739832e

File content as of revision 1:e8b472ec4bb2:

#include "mbed.h"
#include "LPS.h"

I2C i2c(D4,D5);
LPS ps(i2c);

int main(){
    wait(1);
    
    
    if (!ps.init()){
        printf("Failed to autodetect pressure sensor!\r\n");
        while (1);
    }
    
    ps.enableDefault();
    
    while(1){
        float pressure = ps.readPressureMillibars();
        float altitude = ps.pressureToAltitudeMeters(pressure);
        float temperature = ps.readTemperatureC();
        printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature);
    
    wait(1);
    }
}