void setup() {
// put your setup code here, to run once:
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Serial.println("VLX53LOX test started.");
}
void loop() {
Serial.println("----- START TEST ----");
test();
Serial.println("----- END TEST ----");
Serial.println("");
delay(1000);
}
byte val = 0;
int cnt = 0;
while (cnt < 100) { // 1 second waiting time max
delay(10);
val = read_byte_data_at(VL53L0X_REG_RESULT_RANGE_STATUS);
if (val & 0x01) break;
cnt++;
}
if (val & 0x01) Serial.println("ready"); else Serial.println("not ready");
void write_byte_data_at(byte reg, byte data) {
// write data word at address and register
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(data);
Wire.endTransmission();
}
void write_word_data_at(byte reg, uint16_t data) {
// write data word at address and register
byte b0 = (data &0xFF);
byte b1 = ((data >> 8) && 0xFF);
void read_block_data_at(byte reg, int sz) {
int i = 0;
write_byte_data(reg);
Wire.requestFrom(address, sz);
for (i=0; i<sz; i++) {
while (Wire.available() < 1) delay(1);
gbuf = Wire.read();
}
}
uint16_t VL53L0X_decode_vcsel_period(short vcsel_period_reg) {
// Converts the encoded VCSEL period register value into the real
// period in PLL clocks
uint16_t vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
return vcsel_period_pclks;