Leonardo Iandiorio / Mbed 2 deprecated DISCO-SensorsButton

Dependencies:   BSP_B-L475E-IOT01 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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