Santhosh Kumar / Mbed 2 deprecated Gyro_Data_Acquisition1

Dependencies:   mbed X_NUCLEO_IKS01A2

Revision:
4:3e6560c38374
Parent:
3:6f6d19961276
Child:
5:6769e8b30d03
diff -r 6f6d19961276 -r 3e6560c38374 main.cpp
--- a/main.cpp	Mon May 06 18:54:21 2019 +0000
+++ b/main.cpp	Wed May 08 19:31:09 2019 +0000
@@ -6,6 +6,7 @@
 
 /* Retrieve the composing elements of the expansion board */
 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
+static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
 
 InterruptIn mybutton(USER_BUTTON);
 DigitalOut myled(LED1);
@@ -112,6 +113,8 @@
 }
 
 int main() {
+      uint8_t id;
+        int32_t axes[3];
     /* Attach callback to User button press */
   mybutton.fall(&pressed_cb);
   
@@ -140,9 +143,14 @@
 /* Enable Tilt Detection. */
   acc_gyro->enable_tilt_detection();
   
+  magnetometer->enable();
+  
   previous_tick = clock();
   
   printf("\r\n--- Starting new run ---\r\n");
+  
+  magnetometer->read_id(&id);
+  printf("LSM303AGR magnetometer            = 0x%X\r\n", id);
  
   while(1) {
     
@@ -209,7 +217,32 @@
         /* Output data. */
         printf("Free Fall Detected!\r\n");
       }
+      
+      
+    magnetometer->get_m_axes(axes);
+    printf("LSM303AGR [mag/mgauss]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+  /*  //Algo 1 - Please fill the values. 
+    if((axes[0] > fill_the_value) &&  (axes[0] < fill_the_value) &&
+       (axes[1] > fill_the_value) &&  (axes[1] < fill_the_value) &&
+       (axes[2] > fill_the_value) &&  (axes[2] < fill_the_value)) 
+        {
+            printf("Board is tilted on the Left side!\r\n");
+        }  
+        else 
+        {
+            printf("Board is tilted on the Right side\n\r");
+            
+        } */
+        
+    //Condition for right tilt check            
+    if (axes[2] < 30)
+        printf("Message: Board is tilted on the Left side\n\r");
     
+    //Condition for right tilt check
+    if (axes[2] >= 200)
+        printf("Message: Board is tilted on the Right side\n\r");
+            
+        
     }