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

Dependencies:   mbed LPS25HB_I2C

Committer:
kosukesuzuki
Date:
Wed Aug 03 08:42:01 2022 +0000
Revision:
0:03ee8739832e
Child:
1:e8b472ec4bb2
mbed-LPS25HB(nucleo)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kosukesuzuki 0:03ee8739832e 1 #include "mbed.h"
kosukesuzuki 0:03ee8739832e 2 #include "LPS.h"
kosukesuzuki 0:03ee8739832e 3
kosukesuzuki 0:03ee8739832e 4 I2C i2c(D0,D1);
kosukesuzuki 0:03ee8739832e 5 LPS ps(i2c);
kosukesuzuki 0:03ee8739832e 6
kosukesuzuki 0:03ee8739832e 7 int main(){
kosukesuzuki 0:03ee8739832e 8 wait(1);
kosukesuzuki 0:03ee8739832e 9
kosukesuzuki 0:03ee8739832e 10
kosukesuzuki 0:03ee8739832e 11 if (!ps.init()){
kosukesuzuki 0:03ee8739832e 12 printf("Failed to autodetect pressure sensor!\r\n");
kosukesuzuki 0:03ee8739832e 13 while (1);
kosukesuzuki 0:03ee8739832e 14 }
kosukesuzuki 0:03ee8739832e 15
kosukesuzuki 0:03ee8739832e 16 ps.enableDefault();
kosukesuzuki 0:03ee8739832e 17
kosukesuzuki 0:03ee8739832e 18 while(1){
kosukesuzuki 0:03ee8739832e 19 float pressure = ps.readPressureMillibars();
kosukesuzuki 0:03ee8739832e 20 float altitude = ps.pressureToAltitudeMeters(pressure);
kosukesuzuki 0:03ee8739832e 21 float temperature = ps.readTemperatureC();
kosukesuzuki 0:03ee8739832e 22 printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature);
kosukesuzuki 0:03ee8739832e 23
kosukesuzuki 0:03ee8739832e 24 wait(1);
kosukesuzuki 0:03ee8739832e 25 }
kosukesuzuki 0:03ee8739832e 26 }