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.
main.cpp
- Committer:
- gallonm
- Date:
- 2015-10-30
- Revision:
- 19:394c9a4a3046
- Parent:
- 18:6312be3b32d9
- Child:
- 20:b2e0b41a0e6b
File content as of revision 19:394c9a4a3046:
#include "mbed.h"
#include "x_nucleo_6180xa1.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
/* Polling operating modes don`t require callback function that handles IRQ
Callback functions are used only for measure that require interrupt */
#define VL6180X_I2C_SDA I2C_SDA
#define VL6180X_I2C_SCL I2C_SCL
#define RANGE 0
#define ALS 1
/* timer and digital out pin used for debugging */
//Timer timer;
//int start, end;
//DigitalOut pin(PA_15);
DevI2C device_i2c(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
static X_NUCLEO_6180XA1 *board=X_NUCLEO_6180XA1::Instance(&device_i2c);
MeasureData_t data_sensor_top;
/* flags that handle interrupt request */
bool flag_sensor_top=false, flag_stop_measure=false;
/* callback function of the sensor_top */
void SensorTopIRQ(void)
{
flag_sensor_top=true;
board->sensor_top->DisableInterruptMeasureDetectionIRQ();
}
/* callback function of the user button to stop program */
void StopMeasureIRQ(void)
{
flag_stop_measure=true;
}
void DisplayRefresh(OperatingMode op_mode)
{
char str[4];
if(op_mode==range_continuous_interrupt)
{
if(data_sensor_top.range_mm!=0xFFFFFFFF)
{
sprintf(str,"%d",data_sensor_top.range_mm);
board->display->DisplayString(str, strlen(str));
}
}
else if(op_mode==als_continuous_interrupt)
{
if(data_sensor_top.lux!=0xFFFFFFFF)
{
sprintf(str,"%d",data_sensor_top.lux);
board->display->DisplayString(str, strlen(str));
}
}
}
int main()
{
OperatingMode operating_mode, prev_operating_mode;
/* user button used to stop measurements in interrupt mode */
InterruptIn stop_button(USER_BUTTON);
STMPE1600DigiIn measure_type(device_i2c, GPIO_11);
int status, measure;
char str[4];
pc.baud(115200); //change the printf baudrate
status=board->InitBoard();
if(status)
printf("Failed to init the board!\n\r");
stop_button.rise(&StopMeasureIRQ);
measure=measure_type;
if(measure==RANGE)
operating_mode=range_continuous_interrupt;
else if(measure==ALS)
operating_mode=als_continuous_interrupt;
status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, &data_sensor_top, NULL, NULL);
prev_operating_mode=operating_mode;
if(!status)
{
printf("\nStart measurement\n\r");
while(1)
{
if(flag_sensor_top)
{
flag_sensor_top=false;
status=board->sensor_top->HandleIRQ(operating_mode, &data_sensor_top);
if(!status)
{
if(operating_mode==range_continuous_interrupt)
sprintf(str,"%d",data_sensor_top.range_mm);
else if(operating_mode==als_continuous_interrupt)
sprintf(str,"%d",data_sensor_top.lux);
board->display->DisplayString(str, strlen(str));
}
/*else
{
sprintf(str,"%s","----");
board->display->DisplayString(str, strlen(str));
}*/
}
if(flag_stop_measure)
{
status=board->sensor_top->StopMeasurement(prev_operating_mode);
if(status)
printf("Failed to stop measurement!\n\r");
else
printf("Measurement stopped!\n\r");
printf("\nProgram stopped!\n\n\r");
break;
}
measure=measure_type;
if(measure==RANGE)
operating_mode=range_continuous_interrupt;
else if(measure==ALS)
operating_mode=als_continuous_interrupt;
if(operating_mode!=prev_operating_mode)
{
DisplayRefresh(prev_operating_mode);
status=board->sensor_top->StopMeasurement(prev_operating_mode);
prev_operating_mode=operating_mode;
if(status)
printf("Failed to stop measurement!\n\r");
else
printf("Measurement stopped!\n\r");
status=board->sensor_top->StartMeasurement(operating_mode, SensorTopIRQ, &data_sensor_top, NULL, NULL);
if(status)
{
printf("\nFailed to start measurement!\n\r");
break;
}
else
printf("\nStart measurement\n\r");
}
else
DisplayRefresh(operating_mode);
}
}
else
printf("\nFailed to start measurement!\n\r");
delete board;
}

X-NUCLEO-6180XA1 Proximity and Ambient Light Sensor