"""
Distance Crouton (VL53L4CD) Demo Code
Breadstick Innovations
April 16, 2024
https://learn.breadstick.ca/breadstick/breadsticks/support-boards/i2c-devices/distance-crouton
"""
import board
import time
import adafruit_vl53l4cd
crouton_i2c = board.I2C() # Default Breadstick I2C pins D11(SCL) & D12(SDA)
vl53 = adafruit_vl53l4cd.VL53L4CD(crouton_i2c)
# OPTIONAL: can set non-default values
vl53.inter_measurement = 0
vl53.timing_budget = 50
print("VL53L4CD Simple Test.")
print("--------------------")
model_id, module_type = vl53.model_info
print("Model ID: 0x{:0X}".format(model_id))
print("Module Type: 0x{:0X}".format(module_type))
print("Timing Budget: {}".format(vl53.timing_budget))
print("Inter-Measurement: {}".format(vl53.inter_measurement))
print("--------------------")
vl53.start_ranging()
while True:
#while not vl53.data_ready:
# pass
vl53.clear_interrupt()
distance = vl53.distance
plotter_data = (distance,) # Mu's Plotter only displays tuples, this is a single object tuple
print(plotter_data)
print(f'Distance: {distance} cm')
print("")
time.sleep(0.1)