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: mbed X_NUCLEO_IKS01A2
main.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file main.cpp 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 2-December-2016 00007 * @brief Simple Example application for using the X_NUCLEO_IKS01A1 00008 * MEMS Inertial & Environmental Sensor Nucleo expansion board. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Includes */ 00040 #include "mbed.h" 00041 #include "XNucleoIKS01A2.h" 00042 #include <stdio.h> 00043 #include <time.h> 00044 00045 /* Instantiate the expansion board */ 00046 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); 00047 00048 /* Retrieve the composing elements of the expansion board */ 00049 //static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer; 00050 static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; 00051 static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; 00052 int offset = 5; 00053 float F; 00054 00055 00056 /* Helper function for printing floats & doubles */ 00057 static char *print_double(char* str, double v, int decimalDigits=2) 00058 { 00059 int i = 1; 00060 int intPart, fractPart; 00061 int len; 00062 char *ptr; 00063 00064 /* prepare decimal digits multiplicator */ 00065 for (;decimalDigits!=0; i*=10, decimalDigits--); 00066 00067 /* calculate integer & fractinal parts */ 00068 intPart = (int)v; 00069 fractPart = (int)((v-(double)(int)v)*i); 00070 00071 /* fill in integer part */ 00072 sprintf(str, "%i.", intPart); 00073 00074 /* prepare fill in of fractional part */ 00075 len = strlen(str); 00076 ptr = &str[len]; 00077 00078 /* fill in leading fractional zeros */ 00079 for (i/=10;i>1; i/=10, ptr++) { 00080 if (fractPart >= i) { 00081 break; 00082 } 00083 *ptr = '0'; 00084 } 00085 00086 /* fill in (rest of) fractional part */ 00087 sprintf(ptr, "%i", fractPart); 00088 00089 return str; 00090 } 00091 00092 /* Simple main function */ 00093 int main() { 00094 00095 uint8_t id; 00096 //in order to calibrate the temp sensor 00097 float value1, value2; 00098 //char buffer1[32], buffer2[32]; 00099 //int32_t axes[3]; 00100 00101 /* Enable all sensors */ 00102 hum_temp->enable(); 00103 press_temp->enable(); 00104 00105 00106 00107 00108 printf("\r\n--- Starting new run ---\r\n"); 00109 00110 /* Time */ 00111 //Timer t; 00112 set_time(1608670310); 00113 00114 00115 hum_temp->read_id(&id); 00116 00117 press_temp->read_id(&id); 00118 00119 00120 00121 while(1) { 00122 printf("\r\n"); 00123 // t.start(); 00124 hum_temp->get_temperature(&value1); 00125 time_t seconds = time(NULL); 00126 00127 F = ((value1 * 9.0) / 5.0 + 32) - offset; 00128 00129 00130 printf("%u, ", (unsigned int)seconds); 00131 //printf("%f, ", t.read()); 00132 printf(" %7s", print_double(buffer1, F)); 00133 //printf(" %s", buffer); 00134 00135 wait(1200); 00136 } 00137 }
Generated on Wed Jul 13 2022 07:34:39 by
1.7.2