Write an Mbed application that blinks – LED1 when the board is horizontal – LED2 when the board is lying on the long edge – LED3 when the board is lying on the short edge – All LEDs when the board is in none of those positions

Dependencies:   BSP_B-L475E-IOT01 mbed

Files at this revision

API Documentation at this revision

Comitter:
vicara
Date:
Fri Nov 16 11:33:15 2018 +0000
Parent:
1:8681eb2b971d
Commit message:
refactor;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8681eb2b971d -r 527f86cab491 main.cpp
--- a/main.cpp	Wed Nov 14 16:31:32 2018 +0000
+++ b/main.cpp	Fri Nov 16 11:33:15 2018 +0000
@@ -16,75 +16,15 @@
 }
 
 bool is_board_horizontal() {
-    bool is_X_inRange = false;
-    bool is_Y_inRange = false;
-    bool is_Z_inRange = false;
-    
-    int x_value = pDataXYZ[0];
-    int y_value = pDataXYZ[1];
-    int z_value = pDataXYZ[2];
-    
-    if(x_value < 100 && x_value > -100){
-        is_X_inRange = true;
-    }
-    
-    if(y_value < 100 && y_value > -100){
-        is_Y_inRange = true;
-    }
-    
-    if((z_value < 1030 && z_value > 950) || (z_value < -950 && z_value > -1030)){
-        is_Z_inRange = true;
-    }
-    
-    return is_X_inRange && is_Y_inRange && is_Z_inRange;
+    return (pDataXYZ[2] < 1030 && pDataXYZ[2] > 950) || (pDataXYZ[2] < -950 && pDataXYZ[2] > -1030);
 }
 
 bool is_board_vertical_short() {
-    bool is_X_inRange = false;
-    bool is_Y_inRange = false;
-    bool is_Z_inRange = false;
-    
-    int x_value = pDataXYZ[0];
-    int y_value = pDataXYZ[1];
-    int z_value = pDataXYZ[2];
-    
-    if((x_value < -950  && x_value > -1030) || (x_value < 1030 && x_value > 950)){
-        is_X_inRange = true;
-    }
-    
-    if(y_value < 100 && y_value > -100){
-        is_Y_inRange = true;
-    }
-    
-    if(z_value < 100 && z_value > -100){
-        is_Z_inRange = true;
-    }
-    
-    return is_X_inRange && is_Y_inRange && is_Z_inRange;
+    return (pDataXYZ[0] < -950  && pDataXYZ[0] > -1030) || (pDataXYZ[0] < 1030 && pDataXYZ[0] > 950);
 }
 
 bool is_board_vertical_long() {
-    bool is_X_inRange = false;
-    bool is_Y_inRange = false;
-    bool is_Z_inRange = false;
-    
-    int x_value = pDataXYZ[0];
-    int y_value = pDataXYZ[1];
-    int z_value = pDataXYZ[2];
-    
-    if(x_value < 100  && x_value > -100){
-        is_X_inRange = true;
-    }
-    
-    if((y_value < 1030 && y_value > 950) || (y_value < -950 && y_value > -1030)){
-        is_Y_inRange = true;
-    }
-    
-    if(z_value < 100 && z_value > -100){
-        is_Z_inRange = true;
-    }
-    
-    return is_X_inRange && is_Y_inRange && is_Z_inRange;
+    return (pDataXYZ[1] < 1030 && pDataXYZ[1] > 950) || (pDataXYZ[1] < -950 && pDataXYZ[1] > -1030);
 }
 
 void blink_led(int led1_status, int led2_status, int led3_status, DigitalOut led){