initial simple example that prints to terminal
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "MPL3115A2.h" 00003 00004 /* Check out the full featured example application for interfacing to the 00005 * Barometer/Altimeter/Thermometer device at the following URL 00006 * https://developer.mbed.org/users/clemente/code/WIGO_MPL3115A2/ 00007 */ 00008 00009 #define MPL3115A2_I2C_ADDRESS (0x60<<1) 00010 00011 DigitalOut led1(LED1); 00012 00013 // Pin connections for Hexiwear 00014 MPL3115A2 MPL3115A2( PTC11, PTC10, MPL3115A2_I2C_ADDRESS); 00015 /* pos [0] = altimeter or pressure value */ 00016 /* pos [1] = temperature value */ 00017 float sensor_data[2]; 00018 00019 // main() runs in its own thread in the OS 00020 // (note the calls to Thread::wait below for delays) 00021 int main() { 00022 00023 00024 // Set over sampling value (see MPL3115A2.h for details) 00025 MPL3115A2.Oversample_Ratio( OVERSAMPLE_RATIO_64); 00026 // Configure the sensor as Barometer. 00027 MPL3115A2.Barometric_Mode(); 00028 00029 while (true) { 00030 00031 MPL3115A2.getAllData( &sensor_data[0]); 00032 printf("\tPressure: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]); 00033 led1 = !led1; 00034 Thread::wait(500); 00035 } 00036 } 00037
Generated on Sat Jul 16 2022 21:33:53 by
1.7.2