気圧センサLPS22HBのライブラリ
Dependents: Hybrid_IZU2021_MAIN_OS5 Hybrid_IZU2021_MISSION_v2 Hybrid_IZU2021_MAIN Hybrid_IZU2021_MISSION
PQ_LPS22HB.cpp
- Committer:
- tanahashi
- Date:
- 2020-12-15
- Revision:
- 0:9a7d5d7e63be
- Child:
- 1:fdde28032fb5
File content as of revision 0:9a7d5d7e63be:
#include "mbed.h" #include "PQ_LPS22HB.h" LPS22HB :: LPS22HB(I2C &i2c, SA0_t SA0) { _addr = SA0; _i2c = &i2c; _i2c -> frequency(400000); } void LPS22HB :: begin() { cmd[0] = LPS22HB_CTRL_REG1; cmd[1] = 0x40; _i2c -> write(_addr, cmd, 2); } bool LPS22HB :: test() { cmd[0] = LPS22HB_WHO_AM_I; _i2c -> write(_addr, cmd, 1); _i2c -> read(_addr, buff, 1); if(buff[0] == 0xB1) { return true; } else { return false; } } void LPS22HB :: read(float *press, float *temp) { read_press(press); read_temp(temp); } void LPS22HB :: read_press(float *press) { cmd[0] = LPS22HB_PRESS_XL; _i2c -> write(_addr, cmd, 1); _i2c -> read(_addr, buff, 3); *press = (int)(buff[0] | buff[1] << 8 | buff[2] << 16) / 4096.0f; } void LPS22HB :: read_temp(float *temp) { cmd[0] = LPS22HB_TEMP_L; _i2c -> write(_addr, cmd, 1); _i2c -> read(_addr, buff, 2); *temp = (short)(buff[0] | buff[1] << 8) * 0.01; }