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
main.cpp
- Committer:
- bcostm
- Date:
- 2017-04-14
- Revision:
- 6:ff641476ffe3
- Parent:
- 5:2d1980c7ca2d
- Child:
- 7:cccef81dc691
File content as of revision 6:ff641476ffe3:
#include "mbed.h"
#include "stm32l475e_iot01_tsensor.h"
#include "stm32l475e_iot01_hsensor.h"
#include "stm32l475e_iot01_psensor.h"
#include "stm32l475e_iot01_magneto.h"
#include "stm32l475e_iot01_gyro.h"
#include "stm32l475e_iot01_accelero.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
// This object drives both LD3 and LD4 on the board.
// Only one of these LEDs can be driven at a time.
DigitalInOut led3(LED3);
#define LD1_ON {led1 = 1;}
#define LD1_OFF {led1 = 0;}
#define LD1_TOG {led1 = !led1;}
#define LD2_ON {led2 = 1;}
#define LD2_OFF {led2 = 0;}
#define LD2_TOG {led2 = !led2;}
#define LD3_ON {led3.output(); led3 = 1;}
#define LD3_OFF {led3.input();}
#define LD4_ON {led3.output(); led3 = 0;}
#define LD4_OFF {led3.input();}
// Select your demo
//#define DEMO_TEMPERATURE_HUMIDITY_PRESSURE
#define DEMO_MAGNETO_GYRO_ACCELERO
int main()
{
#if defined(DEMO_TEMPERATURE_HUMIDITY_PRESSURE)
float sensor_value = 0;
BSP_TSENSOR_Init();
BSP_HSENSOR_Init();
BSP_PSENSOR_Init();
while(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);
led1 = !led1;
wait(2);
}
#elif defined(DEMO_MAGNETO_GYRO_ACCELERO)
int16_t pDataXYZ[3] = {0};
float pGyroDataXYZ[3] = {0};
BSP_MAGNETO_Init();
BSP_GYRO_Init();
BSP_ACCELERO_Init();
while(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]);
wait(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]);
wait(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]);
wait(2);
}
#else
while(1) {
LD1_ON;
wait(0.5);
LD2_ON;
wait(0.5);
LD3_ON;
wait(0.5);
LD4_ON;
wait(0.5);
LD1_OFF;
wait(0.5);
LD2_OFF;
wait(0.5);
LD3_OFF; // LD4 is also OFF
wait(0.5);
for(int i = 0; i < 10; i++) {
LD1_TOG;
LD2_TOG;
wait(0.2);
}
}
#endif
}