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: X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
X-Nucleo-6180XA1 Hello World Application
This application provides a simple example of usage of X_NUCLEO_6180XA1 library. It provides a measurement of:
- Ambient Light (Lux),
- Distance (millimeters) of an object in front of the on-board sensor.
The values are displayed on the Hyperterminal connected through COM port over USB.
Diff: main.cpp
- Revision:
- 47:04733a0905ba
- Parent:
- 44:3c68d5aa842e
--- a/main.cpp Wed Nov 30 08:26:55 2016 +0000
+++ b/main.cpp Mon Mar 13 19:21:16 2017 +0000
@@ -1,20 +1,34 @@
+/*
+ This VL6180X Expansion board test application performs a range measurement
+ and als measurement in polling mode on the onboard embedded top sensor.
+ The result of both the measures are printed on the serial over.
+ get_distance() and get_lux() are synchronous! They block the caller until the
+ result will be ready.
+*/
+
+
+/* Includes ------------------------------------------------------------------*/
+
#include "mbed.h"
-#include "x_nucleo_6180xa1.h"
+#include "XNucleo6180XA1.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
-/* This VL6180X Expansion board test application performs a range measurement and als measurement in polling mode
- on the onboard embedded top sensor.
- The result of both the measures are printed on the serial over.
- GetDistance and GetLux are synchronous!. So they blocks the caller until the result will be ready
-*/
+
+/* Definitions ---------------------------------------------------------------*/
#define VL6180X_I2C_SDA D14
#define VL6180X_I2C_SCL D15
-static X_NUCLEO_6180XA1 *board=NULL;
+
+/* Variables -----------------------------------------------------------------*/
+
+static XNucleo6180XA1 *board = NULL;
+
+
+/* Functions -----------------------------------------------------------------*/
/*=================================== Main ==================================
Prints on the serial over USB the measured distance and lux.
@@ -22,18 +36,23 @@
=============================================================================*/
int main()
{
- int status;
- uint32_t lux, dist;
- DevI2C *device_i2c =new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
- /* creates the 6180XA1 expansion board singleton obj */
- board=X_NUCLEO_6180XA1::Instance(device_i2c, A3, A2, D13, D2);
- /* init the 6180XA1 expansion board with default values */
- status=board->InitBoard();
- if(status) { printf("Failed to init board!\n\r"); return 0; }
- while(1)
- {
- board->sensor_top->GetDistance(&dist);
- board->sensor_top->GetLux(&lux);
- printf ("Distance: %d, Lux: %d\n\r",dist, lux);
- }
+ int status;
+ uint32_t lux, dist;
+ DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
+
+ /* Creates the 6180XA1 expansion board singleton obj. */
+ board = XNucleo6180XA1::instance(device_i2c, A3, A2, D13, D2);
+
+ /* Initializes the 6180XA1 expansion board with default values. */
+ status = board->init_board();
+ if (status) {
+ printf("Failed to init board!\n\r");
+ return 0;
+ }
+
+ while (true) {
+ board->sensor_top->get_distance(&dist);
+ board->sensor_top->get_lux(&lux);
+ printf ("Distance: %d, Lux: %d\n\r", dist, lux);
+ }
}

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor