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 DigitalOut led(LED1); 00012 InterruptIn button(USER_BUTTON); 00013 int btn_status = 0; 00014 00015 void toggle() { 00016 btn_status = (btn_status + 1) % 6; 00017 } 00018 00019 int main() 00020 { 00021 float sensor_value = 0; 00022 int16_t pDataXYZ[3] = {0}; 00023 float pGyroDataXYZ[3] = {0}; 00024 button.rise(&toggle); 00025 00026 BSP_TSENSOR_Init(); 00027 BSP_HSENSOR_Init(); 00028 BSP_PSENSOR_Init(); 00029 00030 BSP_MAGNETO_Init(); 00031 BSP_GYRO_Init(); 00032 BSP_ACCELERO_Init(); 00033 00034 while(1) { 00035 00036 led = 1; 00037 switch(btn_status){ 00038 case 0: 00039 sensor_value = BSP_TSENSOR_ReadTemp(); 00040 printf("TEMPERATURE = %.2f degC\n\n", sensor_value); 00041 break; 00042 case 1: 00043 sensor_value = BSP_HSENSOR_ReadHumidity(); 00044 printf("HUMIDITY = %.2f %%\n\n", sensor_value); 00045 break; 00046 case 2: 00047 sensor_value = BSP_PSENSOR_ReadPressure(); 00048 printf("PRESSURE is = %.2f mBar\n\n", sensor_value); 00049 break; 00050 case 3: 00051 BSP_MAGNETO_GetXYZ(pDataXYZ); 00052 printf("MAGNETO_X = %d\n", pDataXYZ[0]); 00053 printf("MAGNETO_Y = %d\n", pDataXYZ[1]); 00054 printf("MAGNETO_Z = %d\n\n", pDataXYZ[2]); 00055 break; 00056 case 4: 00057 BSP_GYRO_GetXYZ(pGyroDataXYZ); 00058 printf("GYRO_X = %.2f\n", pGyroDataXYZ[0]); 00059 printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); 00060 printf("GYRO_Z = %.2f\n\n", pGyroDataXYZ[2]); 00061 break; 00062 case 5: 00063 BSP_ACCELERO_AccGetXYZ(pDataXYZ); 00064 printf("ACCELERO_X = %d\n", pDataXYZ[0]); 00065 printf("ACCELERO_Y = %d\n", pDataXYZ[1]); 00066 printf("ACCELERO_Z = %d\n\n", pDataXYZ[2]); 00067 break; 00068 default: 00069 printf("\nThis shouldn't have happened!\n\n"); 00070 break; 00071 } 00072 led = 0; 00073 00074 wait(1); 00075 } 00076 }
Generated on Fri Jul 15 2022 19:50:58 by
1.7.2