NYA Manufacturing
/
LPS331_HelloWorld
Test Program for LPS331 I2C Library.
Diff: main.cpp
- Revision:
- 0:1a3c5ad01539
- Child:
- 2:70ce034cfcfc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 20 15:23:02 2013 +0000 @@ -0,0 +1,43 @@ +#include "mbed.h" +#include "LPS331_I2C.h" + +Serial pc(USBTX, USBRX); +LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH); + + +int main() { + pc.printf("LPS331 Test Program.\r\n"); + + if(lps331.isAvailable()) { + pc.printf("LPS331 is available!\r\n"); + } else { + pc.printf("LPS331 is unavailable!\r\n"); + } + + lps331.setResolution(LPS331_I2C_PRESSURE_AVG_512, LPS331_I2C_TEMP_AVG_128); + lps331.setDataRate(LPS331_I2C_DATARATE_1HZ); + lps331.setActive(true); + + pc.printf("LPS331 Register map.\r\n"); + + for(int i = 0; i < 8; i++) { + pc.printf("%02x: ", i); + for(int j = 0; j < 16; j++) { + char value = lps331._read(j | i << 4); + pc.printf("%02x ", value); + } + pc.printf("\r\n"); + } + + while(true) { + float pres, temp; + + pres = lps331.getPressure(); + temp = lps331.getTemperature(); + + pc.printf("Pressure = %4.2f hPa, Temp = %2.2f C.\r\n", pres, temp); + + wait(1); + } + +}