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: BSP_B-L475E-IOT01 mbed
main.cpp
00001 #include "mbed.h" 00002 00003 // Sensors drivers present in the BSP library 00004 #include "stm32l475e_iot01_tsensor.h" 00005 #include "stm32l475e_iot01_hsensor.h" 00006 #include "stm32l475e_iot01_psensor.h" 00007 #include "stm32l475e_iot01_magneto.h" 00008 #include "stm32l475e_iot01_gyro.h" 00009 #include "stm32l475e_iot01_accelero.h" 00010 00011 #define SENSOR_TYPES 5 00012 00013 DigitalOut led(LED1); 00014 InterruptIn button(USER_BUTTON); 00015 00016 static int sensorCount = 0; 00017 00018 void updateSensorCount() { 00019 sensorCount++; 00020 if (sensorCount > SENSOR_TYPES) { 00021 sensorCount = 0; 00022 } 00023 printf("\n\n"); 00024 } 00025 00026 int main() 00027 { 00028 float sensor_value = 0; 00029 int16_t pDataXYZ[3] = {0}; 00030 float pGyroDataXYZ[3] = {0}; 00031 00032 BSP_TSENSOR_Init(); 00033 BSP_HSENSOR_Init(); 00034 BSP_PSENSOR_Init(); 00035 00036 BSP_MAGNETO_Init(); 00037 BSP_GYRO_Init(); 00038 BSP_ACCELERO_Init(); 00039 00040 // Toggle on button push (rise) 00041 button.rise(&updateSensorCount); 00042 00043 while(1) { 00044 00045 led = 1; 00046 switch(sensorCount) { 00047 case 0: 00048 sensor_value = BSP_TSENSOR_ReadTemp(); 00049 printf("TEMPERATURE = %.2f degC\n", sensor_value); 00050 break; 00051 case 1: 00052 sensor_value = BSP_HSENSOR_ReadHumidity(); 00053 printf("HUMIDITY = %.2f %%\n", sensor_value); 00054 break; 00055 case 2: 00056 sensor_value = BSP_PSENSOR_ReadPressure(); 00057 printf("PRESSURE is = %.2f mBar\n", sensor_value); 00058 break; 00059 case 3: 00060 BSP_MAGNETO_GetXYZ(pDataXYZ); 00061 printf("MAGNETO_X = %d\n", pDataXYZ[0]); 00062 printf("MAGNETO_Y = %d\n", pDataXYZ[1]); 00063 printf("MAGNETO_Z = %d\n", pDataXYZ[2]); 00064 break; 00065 case 4: 00066 BSP_GYRO_GetXYZ(pGyroDataXYZ); 00067 printf("GYRO_X = %.2f\n", pGyroDataXYZ[0]); 00068 printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); 00069 printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); 00070 break; 00071 case 5: 00072 BSP_ACCELERO_AccGetXYZ(pDataXYZ); 00073 printf("ACCELERO_X = %d\n", pDataXYZ[0]); 00074 printf("ACCELERO_Y = %d\n", pDataXYZ[1]); 00075 printf("ACCELERO_Z = %d\n", pDataXYZ[2]); 00076 break; 00077 } 00078 led = 0; 00079 wait(0.5); 00080 } 00081 }
Generated on Sun Jul 17 2022 00:45:09 by
1.7.2