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
main.cpp
00001 /* 00002 This VL6180X Expansion board test application performs a range measurement 00003 and als measurement in polling mode on the onboard embedded top sensor. 00004 The result of both the measures are printed on the serial over. 00005 get_distance() and get_lux() are synchronous! They block the caller until the 00006 result will be ready. 00007 */ 00008 00009 00010 /* Includes ------------------------------------------------------------------*/ 00011 00012 #include "mbed.h" 00013 #include "XNucleo6180XA1.h" 00014 #include <string.h> 00015 #include <stdlib.h> 00016 #include <stdio.h> 00017 #include <assert.h> 00018 00019 00020 /* Definitions ---------------------------------------------------------------*/ 00021 00022 #define VL6180X_I2C_SDA D14 00023 #define VL6180X_I2C_SCL D15 00024 00025 00026 /* Variables -----------------------------------------------------------------*/ 00027 00028 static XNucleo6180XA1 *board = NULL; 00029 00030 00031 /* Functions -----------------------------------------------------------------*/ 00032 00033 /*=================================== Main ================================== 00034 Prints on the serial over USB the measured distance and lux. 00035 The measures are run in single shot polling mode. 00036 =============================================================================*/ 00037 int main() 00038 { 00039 int status; 00040 uint32_t lux, dist; 00041 DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); 00042 00043 /* Creates the 6180XA1 expansion board singleton obj. */ 00044 board = XNucleo6180XA1::instance(device_i2c, A3, A2, D13, D2); 00045 00046 /* Initializes the 6180XA1 expansion board with default values. */ 00047 status = board->init_board(); 00048 if (status) { 00049 printf("Failed to init board!\n\r"); 00050 return 0; 00051 } 00052 00053 while (true) { 00054 board->sensor_top->get_distance(&dist); 00055 board->sensor_top->get_lux(&lux); 00056 printf ("Distance: %d, Lux: %d\n\r", dist, lux); 00057 } 00058 }
Generated on Thu Jul 14 2022 04:19:14 by
1.7.2

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor