Demo program for the MPL3115A2 library.

Dependencies:   MPL3115A2 mbed

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

Revision:
2:0b726b8c8ab9
Parent:
1:5ea71ebc0d82
Child:
3:e2a621ea6976
--- a/main.cpp	Thu May 23 12:44:46 2013 +0000
+++ b/main.cpp	Thu May 30 07:29:41 2013 +0000
@@ -11,16 +11,38 @@
 /* pos [1] = temperature value */
 float sensor_data[2];
 
+void dataready( void);      // callback function for data streaming using Interrupt
+void alttrigger( void);
+
 int main() {
     
-    unsigned int mode=1;
-    
     pc.baud( 230400);
-    pc.printf("MPL3115A2 Barometric mode. [%d]\r\n", wigo_sensor1.getDeviceID());
+    pc.printf("MPL3115A2 Sensor. [%X]\r\n", wigo_sensor1.getDeviceID());
+        
+#if 1
+    // ***** Data acquisition using Interrupt
     
-    wigo_sensor1.Oversample_Ratio( OVERSAMPLE_RATIO_32);
+    // Configure the sensor as Barometer.
     wigo_sensor1.Barometric_Mode();
+    // Set callback function and over sampling value (see MPL3115A2.h for details)
+    wigo_sensor1.DataReady( &dataready, OVERSAMPLE_RATIO_64);
+    // just loop...
+    while( 1)
+    {
+        wait( 1.0);
+        pc.printf(".");
+    }
+#else
+    // ***** Data acquisition using polling method
     
+    // 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.isDataAvailable()) {
@@ -37,4 +59,11 @@
         //
         wait( 0.001);
     }
+#endif    
 }
+
+void dataready( void)
+{
+    wigo_sensor1.getAllData( &sensor_data[0]);
+    pc.printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);
+}