initial simple example that prints to terminal

Dependencies:   MPL3115A2

Committer:
maclobdell
Date:
Sat Aug 13 16:02:39 2016 +0000
Revision:
0:97dd02e37c94
initial simple example that prints to terminal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:97dd02e37c94 1 #include "mbed.h"
maclobdell 0:97dd02e37c94 2 #include "MPL3115A2.h"
maclobdell 0:97dd02e37c94 3
maclobdell 0:97dd02e37c94 4 /* Check out the full featured example application for interfacing to the
maclobdell 0:97dd02e37c94 5 * Barometer/Altimeter/Thermometer device at the following URL
maclobdell 0:97dd02e37c94 6 * https://developer.mbed.org/users/clemente/code/WIGO_MPL3115A2/
maclobdell 0:97dd02e37c94 7 */
maclobdell 0:97dd02e37c94 8
maclobdell 0:97dd02e37c94 9 #define MPL3115A2_I2C_ADDRESS (0x60<<1)
maclobdell 0:97dd02e37c94 10
maclobdell 0:97dd02e37c94 11 DigitalOut led1(LED1);
maclobdell 0:97dd02e37c94 12
maclobdell 0:97dd02e37c94 13 // Pin connections for Hexiwear
maclobdell 0:97dd02e37c94 14 MPL3115A2 MPL3115A2( PTC11, PTC10, MPL3115A2_I2C_ADDRESS);
maclobdell 0:97dd02e37c94 15 /* pos [0] = altimeter or pressure value */
maclobdell 0:97dd02e37c94 16 /* pos [1] = temperature value */
maclobdell 0:97dd02e37c94 17 float sensor_data[2];
maclobdell 0:97dd02e37c94 18
maclobdell 0:97dd02e37c94 19 // main() runs in its own thread in the OS
maclobdell 0:97dd02e37c94 20 // (note the calls to Thread::wait below for delays)
maclobdell 0:97dd02e37c94 21 int main() {
maclobdell 0:97dd02e37c94 22
maclobdell 0:97dd02e37c94 23
maclobdell 0:97dd02e37c94 24 // Set over sampling value (see MPL3115A2.h for details)
maclobdell 0:97dd02e37c94 25 MPL3115A2.Oversample_Ratio( OVERSAMPLE_RATIO_64);
maclobdell 0:97dd02e37c94 26 // Configure the sensor as Barometer.
maclobdell 0:97dd02e37c94 27 MPL3115A2.Barometric_Mode();
maclobdell 0:97dd02e37c94 28
maclobdell 0:97dd02e37c94 29 while (true) {
maclobdell 0:97dd02e37c94 30
maclobdell 0:97dd02e37c94 31 MPL3115A2.getAllData( &sensor_data[0]);
maclobdell 0:97dd02e37c94 32 printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);
maclobdell 0:97dd02e37c94 33 led1 = !led1;
maclobdell 0:97dd02e37c94 34 Thread::wait(500);
maclobdell 0:97dd02e37c94 35 }
maclobdell 0:97dd02e37c94 36 }
maclobdell 0:97dd02e37c94 37