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
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 Thread blinkThread; 00010 Thread fetchThread; 00011 00012 static bool onLongSide; 00013 static bool onShortSide; 00014 static bool flat; 00015 00016 void updateLeds(int led_1, int led_2, int led_3) { 00017 led1 = led_1; 00018 led2 = led_2; 00019 led3 = led_3; 00020 } 00021 00022 void toggleLeds() { 00023 while (true) { 00024 if (flat) { 00025 led1 = !led1; 00026 } else if (onLongSide) { 00027 led2 = !led2; 00028 } else if (onShortSide) { 00029 led3 = !led3; 00030 } else { 00031 led1 = !led1; 00032 led2 = !led2; 00033 led3 = !led3; 00034 } 00035 00036 wait(0.2); 00037 } 00038 } 00039 00040 int main() 00041 { 00042 00043 int16_t pDataXYZ[3] = {0}; 00044 BSP_ACCELERO_Init(); 00045 00046 blinkThread.start(toggleLeds); 00047 00048 00049 while(1) { 00050 BSP_ACCELERO_AccGetXYZ(pDataXYZ); 00051 00052 // Readings 00053 int x = pDataXYZ[0]; 00054 int y = pDataXYZ[1]; 00055 int z = pDataXYZ[2]; 00056 00057 printf("ACCELERO_X = %d\n", x); 00058 printf("ACCELERO_Y = %d\n", y); 00059 printf("ACCELERO_Z = %d\n", z); 00060 00061 onLongSide = x < 0 && y > 950 && z < 100; 00062 onShortSide = (x < -1000 && y < 0 && z < 100) || (x > 950 && y > 0 && z < 100); 00063 flat = x < 50 && x > -50 && y < 50 && y > -50 && z > 1000; 00064 00065 printf("Is on long side: %d\n", onLongSide); 00066 printf("Is on short side: %d\n", onShortSide); 00067 printf("Is on flat side: %d\n", flat); 00068 00069 if (flat) { 00070 updateLeds(1, 0, 0); 00071 } else if (onLongSide) { 00072 updateLeds(0, 1, 0); 00073 } else if (onShortSide) { 00074 updateLeds(0, 0, 1); 00075 } else { 00076 updateLeds(1, 1, 1); 00077 } 00078 00079 printf("=======================================\n"); 00080 wait(0.2); 00081 } 00082 }
Generated on Tue Jul 26 2022 19:58:31 by
1.7.2