'''
实验名称：VL53L1X激光测距
实验平台：核桃派1B
'''

import time, busio, board, adafruit_vl53l1x

# 构建I2C对象，使用核桃派I2C1控制
i2c = busio.I2C(board.SCL1, board.SDA1)

# 构建VL53L1X对象
vl53 = adafruit_vl53l1x.VL53L1X(i2c, address=0x29)

#参数设置
vl53.distance_mode = 1  #1:短距离模式；2:长距离模式。
vl53.timing_budget = 100 #测距持续时间，单位ms。

#传感器信息
print("VL53L1X Simple Test.")
print("--------------------")
model_id, module_type, mask_rev = vl53.model_info
print("Model ID: 0x{:0X}".format(model_id))
print("Module Type: 0x{:0X}".format(module_type))
print("Mask Revision: 0x{:0X}".format(mask_rev))
print("Distance Mode: ", end="")
if vl53.distance_mode == 1:
    print("SHORT")
elif vl53.distance_mode == 2:
    print("LONG")
else:
    print("UNKNOWN")
print("Timing Budget: {}".format(vl53.timing_budget))
print("--------------------")

# 开始测量
vl53.start_ranging()

while True:
    
    if vl53.data_ready:
        print("Distance: {} cm".format(vl53.distance))
        vl53.clear_interrupt()
        time.sleep(0.5)
