Guest User

ToF Range Test

a guest
Sep 7th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import time, sys, signal
  2. import VL53L1X
  3.  
  4. tof0 = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
  5. tof1 = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x31)
  6. tof2 = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x32)
  7.  
  8. tof0.open()
  9. tof1.open()
  10. tof2.open()
  11.  
  12. tof0.start_ranging(1)
  13. tof1.start_ranging(1)
  14. tof2.start_ranging(1)
  15.  
  16. running = True
  17.  
  18. # gracefully quit
  19. def exit_handler(signal, frame):
  20.     global running
  21.     running = False
  22.     tof0.stop_ranging()
  23.     tof1.stop_ranging()
  24.     tof2.stop_ranging()
  25.     sys.exit(0)
  26.  
  27.  
  28. # catch SIGINT
  29. signal.signal(signal.SIGINT, exit_handler)
  30.  
  31. while running:
  32.     a = tof0.get_distance()
  33.     b = tof1.get_distance()
  34.     c = tof2.get_distance()
  35.  
  36.     print("A: {} mm \nB: {} mm\nC: {} mm \n".format(a,b,c))
  37.     time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment