Mbed OS 5.x example, ranging with the VL53L1X Time-of-Flight (ToF) sensor on the X-NUCLEO-53L1A1 expansion board, and 2 VL53L1X Satellite boards, connected to the expansion board.

Dependencies:   X_NUCLEO_53L1A1

Revision:
2:91088f06f39e
Parent:
1:e5cce6b28b6f
Child:
6:e3857da4a7a5
--- a/main.cpp	Fri May 17 12:24:17 2019 +0000
+++ b/main.cpp	Wed Jul 24 14:26:03 2019 +0000
@@ -7,10 +7,11 @@
  *
  * The application supports the centre, on-board, sensor and up to two satellite boards.
  *
- * The User Blue button switches between the currently selected sensor to display range
- * results from.
+ * On STM32-Nucleo boards :
+ *     The User Blue button stops the current measurement and entire program,
+ *     releasing all resources.
  *
- * The Black Reset button is used to restart the program.
+ *     The Black Reset button is used to restart the program.
  *
  * *** NOTE : By default hardlinks U10, U11, U15 & U18, on the underside of
  *            the X-NUCELO-53L0A1 expansion board are not made/OFF.
@@ -33,13 +34,16 @@
 
 #include "mbed.h"
 #include "XNucleo53L1A1.h"
-#include "vl53L1x_I2c.h"
+#include "VL53L1X_I2C.h"
 
 #define VL53L1_I2C_SDA   D14 
 #define VL53L1_I2C_SCL   D15 
 
-#if USER_BUTTON==PC_13  // we are cross compiling for Nucleo-64s
-InterruptIn stop_button(USER_BUTTON);
+#if TARGET_STM  // we are cross compiling for an STM32-Nucleo
+    InterruptIn stop_button(USER_BUTTON);
+#endif
+#if TARGET_Freescale // we are cross-compiling for NXP FRDM boards.
+    InterruptIn stop_button(SW2);
 #endif
 
 /* Installed sensors count */
@@ -49,7 +53,6 @@
 char installedSensors[3];
 
 static XNucleo53L1A1 *board=NULL;
-Serial pc(SERIAL_TX, SERIAL_RX); 
 
 /* interrupt requests */
 volatile bool centerSensor = false;
@@ -183,7 +186,7 @@
 /*
  * Main ranging function
  */
-int range_measure(vl53L1X_DevI2C *device_i2c)
+int range_measure(VL53L1X_DevI2C *device_i2c)
 {
     int status = 0;
 
@@ -226,12 +229,12 @@
 =============================================================================*/
 int main()
 {
-#if USER_BUTTON==PC_13  // we are cross compiling for Nucleo-f401
     stop_button.rise(&switch_measuring_sensor_irq);
     stop_button.enable_irq();
-#endif
-    vl53L1X_DevI2C *dev_I2C = new vl53L1X_DevI2C(VL53L1_I2C_SDA, VL53L1_I2C_SCL);
+    
+    VL53L1X_DevI2C *dev_I2C = new VL53L1X_DevI2C(VL53L1_I2C_SDA, VL53L1_I2C_SCL);
     range_measure(dev_I2C);  // start continuous measures
-return 0;
+    
+    return 0;
 }