Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AQM0802 MPL115 mbed
main.cpp
00001 //********************** 00002 // Barometer and Altimeter 00003 // MPL115A2 sample for mbed 00004 // 00005 // LPC1768 flash=512KB, ADC=12bits 00006 // LPC11U35 flash=64KB, ADC=10bits 00007 // Nucleo ADC=12bits 00008 // 00009 // (C)Copyright 2014 All rights reserved by Y.Onodera 00010 // http://einstlab.web.fc2.com 00011 //********************** 00012 #include "mbed.h" 00013 #include "AQM0802.h" 00014 #include "MPL115.h" 00015 00016 #if defined(TARGET_LPC1768) 00017 I2C i2c(p28,p27); 00018 #endif 00019 // for TG-LPC11U35-501 00020 #if defined(TARGET_LPC11U35_501) 00021 I2C i2c(P0_5,P0_4); 00022 #endif 00023 // for Nucleo 00024 #if defined(TARGET_NUCLEO_F401RE) 00025 I2C i2c(D14,D15); 00026 #endif 00027 00028 AQM0802 lcd(i2c); 00029 MPL115A2 mpl115a2(i2c); 00030 00031 #define T0 288.15 00032 #define dT 0.0065 00033 #define P0 101325.0 00034 #define g 9.80665 00035 #define R 287.052 00036 double GetAltitude(double p, double t){ 00037 00038 return (t+273.15)/dT*(pow((P0/p),dT*R/g)-1); 00039 00040 } 00041 00042 int main() { 00043 00044 char msg[10]; 00045 int p, t, a; 00046 00047 sprintf(msg,"Barometer"); 00048 lcd.locate(0,0); 00049 lcd.print(msg); 00050 sprintf(msg,"Altimeter"); 00051 lcd.locate(0,1); 00052 lcd.print(msg); 00053 wait(1); 00054 00055 while(1) { 00056 00057 p = ( (double)mpl115a2.pressure()/16.0 * (115.0-50.0)/1023.0 + 50.0 ) * 1000.0; 00058 t = 25.0 - ((double)mpl115a2.temperature() - 498.0) / 5.35; 00059 a = GetAltitude(p,t); 00060 00061 sprintf(msg,"%6dPa",p); 00062 lcd.locate(0,0); 00063 lcd.print(msg); 00064 sprintf(msg,"%4dm%2dC", a, t); 00065 lcd.locate(0,1); 00066 lcd.print(msg); 00067 wait(1); 00068 } 00069 00070 } 00071 00072
Generated on Wed Jul 20 2022 06:43:02 by
1.7.2