initial simple example that prints to terminal

Dependencies:   MPL3115A2

main.cpp

Committer:
maclobdell
Date:
2016-08-13
Revision:
0:97dd02e37c94

File content as of revision 0:97dd02e37c94:

#include "mbed.h"
#include "MPL3115A2.h"

/*  Check out the full featured example application for interfacing to the 
 *  Barometer/Altimeter/Thermometer device at the following URL
 *  https://developer.mbed.org/users/clemente/code/WIGO_MPL3115A2/
*/
 
#define MPL3115A2_I2C_ADDRESS (0x60<<1)

DigitalOut led1(LED1);

// Pin connections for Hexiwear
MPL3115A2 MPL3115A2( PTC11, PTC10, MPL3115A2_I2C_ADDRESS);
/* pos [0] = altimeter or pressure value */
/* pos [1] = temperature value */
float sensor_data[2];

// main() runs in its own thread in the OS
// (note the calls to Thread::wait below for delays)
int main() {
    
   
    // Set over sampling value (see MPL3115A2.h for details)
    MPL3115A2.Oversample_Ratio( OVERSAMPLE_RATIO_64);
    // Configure the sensor as Barometer.
    MPL3115A2.Barometric_Mode();
    
    while (true) {
    
        MPL3115A2.getAllData( &sensor_data[0]);
        printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);    
        led1 = !led1;
        Thread::wait(500);
    }
}