code.py
 1  # SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  Rangefinder byuit around the Garmin LidarLite
 7  
 8  Adafruit invests time and resources providing this open source code.
 9  Please support Adafruit and open source hardware by purchasing
10  products from Adafruit!
11  
12  Written by Dave Astels for Adafruit Industries
13  Copyright (c) 2018 Adafruit Industries
14  Licensed under the MIT license.
15  
16  All text above must be included in any redistribution.
17  """
18  import time
19  import busio
20  import board
21  import adafruit_lidarlite
22  import adafruit_ht16k33.segments
23  
24  i2c = busio.I2C(board.SCL, board.SDA)
25  
26  sensor = adafruit_lidarlite.LIDARLite(i2c)
27  display = adafruit_ht16k33.segments.Seg7x4(i2c)
28  
29  while True:
30      try:
31          display.print(sensor.distance)
32      except RuntimeError as e:
33          # If we get a reading error, just print it and keep truckin'
34          print(e)
35      time.sleep(0.5)