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 STATE_TEMP 0 00012 #define STATE_HUMIDITY 1 00013 #define STATE_PRESSURE 2 00014 #define STATE_MAGNETO 3 00015 #define STATE_GYRO 4 00016 #define STATE_ACCELERO 5 00017 #define LAST_STATE 5 00018 00019 InterruptIn button(USER_BUTTON); 00020 DigitalOut led(LED1); 00021 00022 static uint8_t state = 0; 00023 00024 void change_state() 00025 { 00026 if (state == LAST_STATE) { 00027 state = STATE_TEMP; 00028 } else { 00029 state++; 00030 } 00031 } 00032 00033 int main() 00034 { 00035 00036 button.rise(&change_state); 00037 00038 float sensor_value = 0; 00039 int16_t pDataXYZ[3] = {0}; 00040 float pGyroDataXYZ[3] = {0}; 00041 00042 BSP_TSENSOR_Init(); 00043 BSP_HSENSOR_Init(); 00044 00045 BSP_PSENSOR_Init(); 00046 00047 BSP_MAGNETO_Init(); 00048 BSP_GYRO_Init(); 00049 BSP_ACCELERO_Init(); 00050 00051 while(1) { 00052 00053 led = 1; 00054 wait(1); 00055 00056 switch (state) { 00057 case STATE_TEMP: 00058 sensor_value = BSP_TSENSOR_ReadTemp(); 00059 printf("\nTEMPERATURE = %.2f degC\n", sensor_value); 00060 break; 00061 case STATE_HUMIDITY: 00062 sensor_value = BSP_HSENSOR_ReadHumidity(); 00063 printf("HUMIDITY = %.2f %%\n", sensor_value); 00064 break; 00065 case STATE_PRESSURE: 00066 sensor_value = BSP_PSENSOR_ReadPressure(); 00067 printf("PRESSURE is = %.2f mBar\n", sensor_value); 00068 break; 00069 case STATE_MAGNETO: 00070 BSP_MAGNETO_GetXYZ(pDataXYZ); 00071 printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); 00072 printf("MAGNETO_Y = %d\n", pDataXYZ[1]); 00073 printf("MAGNETO_Z = %d\n", pDataXYZ[2]); 00074 break; 00075 case STATE_GYRO: 00076 BSP_GYRO_GetXYZ(pGyroDataXYZ); 00077 printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); 00078 printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); 00079 printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); 00080 break; 00081 case STATE_ACCELERO: 00082 BSP_ACCELERO_AccGetXYZ(pDataXYZ); 00083 printf("\nACCELERO_X = %d\n", pDataXYZ[0]); 00084 printf("ACCELERO_Y = %d\n", pDataXYZ[1]); 00085 printf("ACCELERO_Z = %d\n", pDataXYZ[2]); 00086 break; 00087 } 00088 00089 led = 0; 00090 wait(1); 00091 } 00092 }
Generated on Sat Jul 16 2022 18:41:25 by
1.7.2