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 #include "stm32l475e_iot01_accelero.h" 00004 00005 DigitalOut led1(LED1); 00006 DigitalOut led2(LED2); 00007 DigitalOut led3(LED3); 00008 00009 int main() 00010 { 00011 int16_t pDataXYZ[3] = {0}; 00012 00013 BSP_ACCELERO_Init(); 00014 00015 while(1) { 00016 00017 wait(1); 00018 00019 BSP_ACCELERO_AccGetXYZ(pDataXYZ); 00020 printf("\nACCELERO_X = %d\n", pDataXYZ[0]); 00021 printf("ACCELERO_Y = %d\n", pDataXYZ[1]); 00022 printf("ACCELERO_Z = %d\n", pDataXYZ[2]); 00023 00024 int16_t x_data = pDataXYZ[0]; 00025 int16_t y_data = pDataXYZ[1]; 00026 int16_t z_data = pDataXYZ[2]; 00027 00028 if(abs(z_data)>= 970 && abs(z_data) <= 1030 ) 00029 { 00030 printf("the board is in horizontal position\n"); 00031 led1 = 1; 00032 led2 = 0; 00033 led3 = 0; 00034 wait(1); 00035 led1 = 0; 00036 } else { led1 = 0;} 00037 00038 if(abs(x_data)>= 970 && abs(x_data) <= 1030 ){ 00039 printf("the board is in the short edge\n"); 00040 led2 = 1; 00041 led1 = 0; 00042 led3 = 0; 00043 wait(1); 00044 led2 = 0; 00045 } else { led2 = 0; } 00046 00047 if(abs(y_data)>= 970 && abs(y_data) <= 1030 ){ 00048 printf("the board is in the long edge\n"); 00049 led3 = 1; 00050 led2 = 0; 00051 led1 = 0; 00052 wait(1); 00053 led3 = 0; 00054 } else { led3 = 0; } 00055 00056 if(!(abs(z_data)>= 970 && abs(z_data) <= 1030) && !(abs(x_data)>= 970 && abs(x_data) <= 1030) && !(abs(y_data)>= 970 && abs(y_data) <= 1030)){ 00057 printf("unknown position\n"); 00058 led1 = 1; 00059 led2 = 1; 00060 led3 = 1; 00061 wait(1); 00062 led1 = 0; 00063 led2 = 0; 00064 led3 = 0; 00065 } else { 00066 led1 = 0; 00067 led2 = 0; 00068 led3 = 0; 00069 } 00070 00071 } 00072 }
Generated on Tue Jul 19 2022 09:12:46 by
1.7.2