hw

Dependencies:   mbed LPS22HB LSM6DSL LSM303AGR HTS221

Revision:
2:efaeb347f9c7
Parent:
0:9c859fc3ee1a
diff -r 9fa494501f6f -r efaeb347f9c7 main.cpp
--- a/main.cpp	Thu Apr 23 07:46:46 2020 +0000
+++ b/main.cpp	Thu Apr 23 08:11:36 2020 +0000
@@ -3,7 +3,14 @@
 #include "XNucleoIKS01A2.h"
 
 /* Instantiate the expansion board */
+static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
 
+/* Retrieve the composing elements of the expansion board */
+static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
+static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
+static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
+static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
+static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
 
 // Create a DigitalOut objects for the LED
 DigitalOut led(LED1);
@@ -35,7 +42,14 @@
     
     /* Create a sensor shield object */
     // static X_CUBE_MEMS *Sensors = X_CUBE_MEMS::Instance();
-    static XNucleoIKS01A2 *Sensors = XNucleoIKS01A2::instance(D14, D15, D4, D5);
+
+    /* Enable all sensors */
+    hum_temp->enable();
+    press_temp->enable();
+    magnetometer->enable();
+    accelerometer->enable();
+    acc_gyro->enable_x();
+    acc_gyro->enable_g();
 
       /* Attach a function to be called by the Ticker objects at a specific interval in seconds*/
     blinky.attach(&blinky_handler, 0.5);
@@ -44,9 +58,9 @@
     while(1) {
         if(measurements_update == true){
             /* Read the environmental sensors  */
-            Sensors->ht_sensor->get_temperature((float *)&TEMPERATURE_C);
-            Sensors->ht_sensor->get_humidity((float *)&HUMIDITY);
-            Sensors->pt_sensor->get_pressure((float *)&PRESSURE);
+            hum_temp->get_temperature((float *)&TEMPERATURE_C);
+            hum_temp->get_humidity((float *)&HUMIDITY);
+            press_temp->get_pressure((float *)&PRESSURE);
             
             TEMPERATURE_F = (TEMPERATURE_C * 1.8f) + 32.0f; //Convert the temperature from Celsius to Fahrenheit
             TEMPERATURE_K = (TEMPERATURE_C + 273.15f);          //Convert the temperature from Celsius to Kelvin