This program is for Cansat made with BreadBoard which have pressure sensor LPS331. This program is based on http://mbed.org/users/nyamfg/code/LPS331_HelloWorld/

Dependencies:   mbed

Revision:
3:cb51cc4a041d
Parent:
2:70ce034cfcfc
Child:
4:4c01d79dd741
--- a/main.cpp	Mon Oct 21 16:41:09 2013 +0000
+++ b/main.cpp	Wed Jun 18 10:35:42 2014 +0000
@@ -4,8 +4,13 @@
 Serial pc(USBTX, USBRX);
 LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH);
 
+DigitalIn JP(p6);
+DigitalOut myled1(LED1);
+LocalFileSystem local("local"); 
+Timer t;
 
 int main() {
+
     pc.printf("LPS331 Test Program.\r\n");
     
     if(lps331.isAvailable()) {
@@ -17,41 +22,36 @@
     lps331.setResolution(LPS331_I2C_PRESSURE_AVG_512, LPS331_I2C_TEMP_AVG_128);
     lps331.setDataRate(LPS331_I2C_DATARATE_7HZ);
     lps331.setActive(true);
-    
-    pc.printf("LPS331 Register map.\r\n");
+              
+    FILE *fp = fopen("/local/data.txt", "a");
+    fprintf(fp,"**********\r\n");
+    fclose(fp);
 
-    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");
-    }
+    t.start();
     
-    pc.printf("LPS331 Register map(multibyte read test).\r\n");
-    
-    for(int i = 0; i < 8; i++) {
-        char data[16];
-        lps331._read_multibyte(i << 4, data, 16);
-        pc.printf("%02x: ", i);
-        for(int j = 0; j < 16; j++) {
-            pc.printf("%02x ", data[j]);
-        }
-        pc.printf("\r\n");
-    }
-    
-    wait(2.0);
-                
     while(true) {
         float pres, temp;
+        int ms;
+
+        if(JP==0) {
+            break;
+        }
         
+        FILE *fp = fopen("/local/data.txt", "a");
+
         pres = lps331.getPressure();
         temp = lps331.getTemperature();
         
-        pc.printf("%f,%f\r\n", pres, temp);
+        ms = t.read_ms();
+                              
+        pc.printf(  "%10d,%6.2f,%4.1f\r\n", ms, pres, temp);
+        fprintf(fp, "%10d,%6.2f,%4.1f\r\n", ms, pres, temp);
+
+        fclose(fp);
         
-        wait(1/7.0);
+        wait(0.05);
+        myled1 = 1;
+        wait(0.05);
+        myled1 = 0;
     }
-
 }