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
Diff: main.cpp
- Revision:
- 1:3a872c90df39
- Parent:
- 0:0cc3bd737dcb
--- a/main.cpp Thu Nov 08 16:47:56 2018 +0000 +++ b/main.cpp Thu Nov 15 16:46:40 2018 +0000 @@ -8,7 +8,20 @@ #include "stm32l475e_iot01_gyro.h" #include "stm32l475e_iot01_accelero.h" +#define SENSOR_TYPES 5 + DigitalOut led(LED1); +InterruptIn button(USER_BUTTON); + +static int sensorCount = 0; + +void updateSensorCount() { + sensorCount++; + if (sensorCount > SENSOR_TYPES) { + sensorCount = 0; + } + printf("\n\n"); +} int main() { @@ -23,44 +36,46 @@ BSP_MAGNETO_Init(); BSP_GYRO_Init(); BSP_ACCELERO_Init(); + + // Toggle on button push (rise) + button.rise(&updateSensorCount); while(1) { led = 1; - - sensor_value = BSP_TSENSOR_ReadTemp(); - printf("\nTEMPERATURE = %.2f degC\n", sensor_value); - - sensor_value = BSP_HSENSOR_ReadHumidity(); - printf("HUMIDITY = %.2f %%\n", sensor_value); - - sensor_value = BSP_PSENSOR_ReadPressure(); - printf("PRESSURE is = %.2f mBar\n", sensor_value); - + switch(sensorCount) { + case 0: + sensor_value = BSP_TSENSOR_ReadTemp(); + printf("TEMPERATURE = %.2f degC\n", sensor_value); + break; + case 1: + sensor_value = BSP_HSENSOR_ReadHumidity(); + printf("HUMIDITY = %.2f %%\n", sensor_value); + break; + case 2: + sensor_value = BSP_PSENSOR_ReadPressure(); + printf("PRESSURE is = %.2f mBar\n", sensor_value); + break; + case 3: + BSP_MAGNETO_GetXYZ(pDataXYZ); + printf("MAGNETO_X = %d\n", pDataXYZ[0]); + printf("MAGNETO_Y = %d\n", pDataXYZ[1]); + printf("MAGNETO_Z = %d\n", pDataXYZ[2]); + break; + case 4: + BSP_GYRO_GetXYZ(pGyroDataXYZ); + printf("GYRO_X = %.2f\n", pGyroDataXYZ[0]); + printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); + printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); + break; + case 5: + BSP_ACCELERO_AccGetXYZ(pDataXYZ); + printf("ACCELERO_X = %d\n", pDataXYZ[0]); + printf("ACCELERO_Y = %d\n", pDataXYZ[1]); + printf("ACCELERO_Z = %d\n", pDataXYZ[2]); + break; + } led = 0; - - wait(1); - - led = 1; - - BSP_MAGNETO_GetXYZ(pDataXYZ); - printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); - printf("MAGNETO_Y = %d\n", pDataXYZ[1]); - printf("MAGNETO_Z = %d\n", pDataXYZ[2]); - - BSP_GYRO_GetXYZ(pGyroDataXYZ); - printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); - printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); - printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); - - BSP_ACCELERO_AccGetXYZ(pDataXYZ); - printf("\nACCELERO_X = %d\n", pDataXYZ[0]); - printf("ACCELERO_Y = %d\n", pDataXYZ[1]); - printf("ACCELERO_Z = %d\n", pDataXYZ[2]); - - led = 0; - - wait(1); - + wait(0.5); } }