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.
Fork of Environmental_sheild_F4 by
main.cpp
00001 #include "mbed.h" 00002 #include "nucleo-f401re.h" 00003 #include "x_nucleo_ike01x1_pressure.h" 00004 #include "x_nucleo_ike01x1_uv.h" 00005 #include "x_nucleo_ike01x1_hum_temp.h" 00006 //------------------------------------ 00007 // Hyperterminal configuration 00008 // 9600 bauds, 8-bit data, no parity 00009 //------------------------------------ 00010 uint8_t PRESInit=0; 00011 uint8_t UVInit=0; 00012 uint8_t HumTempInit=0; 00013 /*Global variables */ 00014 uint8_t HumTempId=0; 00015 uint8_t PressID=0; 00016 int dec_precision = 2; 00017 volatile float UVI_Value; 00018 volatile float PRESSURE_Value; 00019 volatile float HUMIDITY_Value; 00020 volatile float TEMPERATURE_Value; 00021 void floatToInt(float in, int32_t *out_int, int32_t *out_dec, int32_t dec_prec); 00022 Serial pc(SERIAL_TX, SERIAL_RX); 00023 00024 DigitalOut myled(LED1); 00025 00026 int main() 00027 { 00028 00029 int mul = 1; 00030 for(int i = 0; i < dec_precision; i++) 00031 mul = mul*10; 00032 00033 if(!BSP_HUM_TEMP_isInitialized()) { 00034 BSP_HUM_TEMP_Init(); //This also Inits I2C interface from here. 00035 } 00036 HumTempId = BSP_HUM_TEMP_ReadID(); 00037 if(HumTempId==I_AM_HTS221){ 00038 HumTempInit=1; 00039 } 00040 /*End Temp Sensor Init*/ 00041 00042 /*Initialize the pressure sensors*/ 00043 if(!BSP_PRESSURE_isInitialized()) { 00044 BSP_PRESSURE_Init(); //This also Inits I2C interface from here. 00045 PRESInit=1; 00046 } 00047 PressID = BSP_PRESSURE_ReadID(); 00048 00049 int32_t d1, d2, d3, d4; 00050 00051 pc.printf("Hello World !\n"); 00052 while(1) { 00053 wait(1); 00054 00055 if(BSP_HUM_TEMP_isInitialized()) 00056 { 00057 BSP_HUM_TEMP_GetHumidity((float *)&HUMIDITY_Value); 00058 BSP_HUM_TEMP_GetTemperature((float *)&TEMPERATURE_Value); 00059 00060 floatToInt(HUMIDITY_Value, &d1, &d2, mul); 00061 floatToInt(TEMPERATURE_Value, &d3, &d4, mul); 00062 pc.printf("H: %d.%02d T: %d.%02d", d1, d2, d3, d4); 00063 00064 } 00065 00066 if(BSP_PRESSURE_isInitialized()) 00067 { 00068 BSP_PRESSURE_GetPressure((float *)&PRESSURE_Value); 00069 floatToInt(PRESSURE_Value, &d1, &d2, mul); 00070 pc.printf(" P: %d.%02d\n", d1, d2); 00071 00072 } 00073 00074 if(BSP_UV_isInitialized()) 00075 { 00076 BSP_UV_GetIndex((float *)&UVI_Value); 00077 floatToInt(UVI_Value, &d1, &d2, mul); 00078 pc.printf("UV: %d.%02d\n", d1, d2); 00079 } 00080 00081 pc.printf("Done"); 00082 myled = !myled; 00083 } 00084 } 00085 void floatToInt(float in, int32_t *out_int, int32_t *out_dec, int32_t dec_prec) 00086 { 00087 *out_int = (int32_t)in; 00088 in = in - (float)(*out_int); 00089 *out_dec = (int32_t)(in*dec_prec); 00090 }
Generated on Sat Jul 16 2022 01:43:34 by
1.7.2
