Program to demonstrate lighting an led via a command line command

Dependencies:   LPS331_I2C

Files at this revision

API Documentation at this revision

Comitter:
bhimebau
Date:
Wed Oct 06 13:29:15 2021 +0000
Parent:
0:f7d9662c6d11
Commit message:
Added Pressure Stuff

Changed in this revision

LPS331_I2C.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS331_I2C.lib	Wed Oct 06 13:29:15 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/nyamfg/code/LPS331_I2C/#b7d3d6e82049
--- a/main.cpp	Wed Sep 22 13:41:56 2021 +0000
+++ b/main.cpp	Wed Oct 06 13:29:15 2021 +0000
@@ -6,12 +6,13 @@
 #include "mbed.h"
 #include "platform/mbed_thread.h"
 #include <string.h>
-
+#include "LPS331_I2C.h"
 
 // Blinking rate in milliseconds
 #define BLINKING_RATE_MS                                                    500
 
 Serial pc(USBTX, USBRX); // tx, rx
+LPS331_I2C lps331(PB_7, PB_6, LPS331_I2C_SA0_HIGH);
 
 int main()
 {
@@ -19,6 +20,12 @@
     char ch;
     unsigned char index = 0;
 
+    if(lps331.isAvailable()) {
+        pc.printf("LPS331 is available!\r\n");
+    } else {
+        pc.printf("LPS331 is unavailable!\r\n");
+    }
+
     // Initialise the digital pin LED1 as an output
     DigitalOut led(LED1);
     pc.printf("L432> ");    
@@ -42,3 +49,60 @@
         pc.printf("L432> ");
     }
 }
+
+/* 
+#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_7HZ);
+    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");
+    }
+    
+    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;
+        
+        pres = lps331.getPressure();
+        temp = lps331.getTemperature();
+        
+        pc.printf("%f,%f\r\n", pres, temp);
+        
+        wait(1/7.0);
+    }
+*/