Example code AN4545
22/27 DocID026571 Rev 1
int range;
range=ReadByte(0x062);
return range;
}
///////////////////////////////////////////////////////////////////
// clear interrupts
///////////////////////////////////////////////////////////////////
int VL6180X_Clear_Interrupts() {
WriteByte(0x015,0x07);
return 0;
}
///////////////////////////////////////////////////////////////////
// Main Program loop
///////////////////////////////////////////////////////////////////
int main()
{
int range;
// load settings onto VL6180X
VL6180X_Init();
while (1){
// start single range measurement
VL6180X_Start_Range();
// poll the VL6180X till new sample ready
VL6180X_Poll_Range();
// read range result
range = VL6180X_Read_Range();
// clear the interrupt on VL6180X
VL6180X_Clear_Interrupts();
// send range to pc by serial
pc.printf("%d\r\n", range);
wait(0.1);
}
}
To change the example above to continuous mode:
1. In the VL6180X_Start_Range() function change the data written to VL6180X from 0x01
to 0x03.
2. In the while loop, move the function call for VL6180X_Start_Range() to outside the
while loop, immediately after the VL6180X_Init() call.