Test Program for LPS331 I2C Library.

Dependencies:   LPS331_I2C mbed

Committer:
nyamfg
Date:
Sun Oct 20 15:23:02 2013 +0000
Revision:
0:1a3c5ad01539
Child:
2:70ce034cfcfc
1st release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyamfg 0:1a3c5ad01539 1 #include "mbed.h"
nyamfg 0:1a3c5ad01539 2 #include "LPS331_I2C.h"
nyamfg 0:1a3c5ad01539 3
nyamfg 0:1a3c5ad01539 4 Serial pc(USBTX, USBRX);
nyamfg 0:1a3c5ad01539 5 LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH);
nyamfg 0:1a3c5ad01539 6
nyamfg 0:1a3c5ad01539 7
nyamfg 0:1a3c5ad01539 8 int main() {
nyamfg 0:1a3c5ad01539 9 pc.printf("LPS331 Test Program.\r\n");
nyamfg 0:1a3c5ad01539 10
nyamfg 0:1a3c5ad01539 11 if(lps331.isAvailable()) {
nyamfg 0:1a3c5ad01539 12 pc.printf("LPS331 is available!\r\n");
nyamfg 0:1a3c5ad01539 13 } else {
nyamfg 0:1a3c5ad01539 14 pc.printf("LPS331 is unavailable!\r\n");
nyamfg 0:1a3c5ad01539 15 }
nyamfg 0:1a3c5ad01539 16
nyamfg 0:1a3c5ad01539 17 lps331.setResolution(LPS331_I2C_PRESSURE_AVG_512, LPS331_I2C_TEMP_AVG_128);
nyamfg 0:1a3c5ad01539 18 lps331.setDataRate(LPS331_I2C_DATARATE_1HZ);
nyamfg 0:1a3c5ad01539 19 lps331.setActive(true);
nyamfg 0:1a3c5ad01539 20
nyamfg 0:1a3c5ad01539 21 pc.printf("LPS331 Register map.\r\n");
nyamfg 0:1a3c5ad01539 22
nyamfg 0:1a3c5ad01539 23 for(int i = 0; i < 8; i++) {
nyamfg 0:1a3c5ad01539 24 pc.printf("%02x: ", i);
nyamfg 0:1a3c5ad01539 25 for(int j = 0; j < 16; j++) {
nyamfg 0:1a3c5ad01539 26 char value = lps331._read(j | i << 4);
nyamfg 0:1a3c5ad01539 27 pc.printf("%02x ", value);
nyamfg 0:1a3c5ad01539 28 }
nyamfg 0:1a3c5ad01539 29 pc.printf("\r\n");
nyamfg 0:1a3c5ad01539 30 }
nyamfg 0:1a3c5ad01539 31
nyamfg 0:1a3c5ad01539 32 while(true) {
nyamfg 0:1a3c5ad01539 33 float pres, temp;
nyamfg 0:1a3c5ad01539 34
nyamfg 0:1a3c5ad01539 35 pres = lps331.getPressure();
nyamfg 0:1a3c5ad01539 36 temp = lps331.getTemperature();
nyamfg 0:1a3c5ad01539 37
nyamfg 0:1a3c5ad01539 38 pc.printf("Pressure = %4.2f hPa, Temp = %2.2f C.\r\n", pres, temp);
nyamfg 0:1a3c5ad01539 39
nyamfg 0:1a3c5ad01539 40 wait(1);
nyamfg 0:1a3c5ad01539 41 }
nyamfg 0:1a3c5ad01539 42
nyamfg 0:1a3c5ad01539 43 }