Demo program for the MPL3115A2 library.

Dependencies:   MPL3115A2 mbed

Example program for MPL3115 sensor. Added code for data acquisition using Interrupt.

Files at this revision

API Documentation at this revision

Comitter:
clemente
Date:
Sun Sep 22 11:18:08 2013 +0000
Parent:
5:0f26cb937640
Child:
7:97f5edf7d270
Commit message:
Added an exmple to read the maximum and minimum value using the new functions.

Changed in this revision

MPL3115A2.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
--- a/MPL3115A2.lib	Sun Aug 25 21:48:37 2013 +0000
+++ b/MPL3115A2.lib	Sun Sep 22 11:18:08 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/clemente/code/MPL3115A2/#59e9ba115d0a
+http://mbed.org/users/clemente/code/MPL3115A2/#75a5960adf5c
--- a/main.cpp	Sun Aug 25 21:48:37 2013 +0000
+++ b/main.cpp	Sun Sep 22 11:18:08 2013 +0000
@@ -24,7 +24,7 @@
     pc.baud( 230400);
     pc.printf("MPL3115A2 Sensor. [%X]\r\n", wigo_sensor1.getDeviceID());
         
-#if 0
+#if 1
     // ***** Data acquisition using Interrupt
     
     // Configure the sensor as Barometer.
@@ -37,7 +37,8 @@
         wait( 1.0);
         pc.printf(".");
     }
-#else
+#endif
+
 #if 0
     // ***** Data acquisition using polling method
     
@@ -64,7 +65,39 @@
         //
         wait( 1.0);
     }
-#else
+#endif
+
+#if 0
+    // ***** Data acquisition using polling method with Max and Min values visualization
+    
+    // Configure the sensor as Barometer.
+    unsigned int mode=1;
+    
+    // Set over sampling value (see MPL3115A2.h for details)
+    wigo_sensor1.Oversample_Ratio( OVERSAMPLE_RATIO_64);
+    // Configure the sensor as Barometer.
+    wigo_sensor1.Barometric_Mode();
+
+    while(1) {
+        //
+        if ( wigo_sensor1.getAllData( &sensor_data[0])) {
+            pc.printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);
+            if ( (mode % 20)==0) {
+                sensor_data[0] = sensor_data[1] = 0.0;
+                wigo_sensor1.getAllMaximumData( &sensor_data[0]);
+                pc.printf("\tMaxPress: %f\tMaxTemp: %f\r\n", sensor_data[0], sensor_data[1]);
+                sensor_data[0] = sensor_data[1] = 0.0;
+                wigo_sensor1.getAllMinimumData( &sensor_data[0]);
+                pc.printf("\tMinPress: %f\tMinTemp: %f\r\n", sensor_data[0], sensor_data[1]);                    
+            }
+            mode++;
+        }
+        //
+        wait( 1.0);
+    }
+#endif
+
+#if 0
     // ***** Data acquisition in RAW mode using polling method
 
     // Create a buffer for raw data
@@ -76,7 +109,7 @@
     wigo_sensor1.Oversample_Ratio( OVERSAMPLE_RATIO_64);
     // Configure the sensor as Barometer.
     wigo_sensor1.Barometric_Mode();
-
+    
     while(1) {
         //
         if ( wigo_sensor1.getAllDataRaw( &raw_data[0])) {
@@ -94,7 +127,7 @@
     }
     
 #endif    
-#endif    
+    
 }
 
 void dataready( void)