You've already forked uiflow-micropython
mirror of
https://github.com/m5stack/uiflow-micropython.git
synced 2026-05-20 10:39:27 -07:00
4b8dbf65b9
Signed-off-by: lbuque <1102390310@qq.com>
17 lines
421 B
Python
17 lines
421 B
Python
# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import time
|
|
from machine import I2C, Pin
|
|
from unit import ToFUnit
|
|
|
|
# Initialize I2C bus and sensor.
|
|
i2c = I2C(0, scl=Pin(1), sda=Pin(2), freq=400000)
|
|
tof = ToFUnit(i2c, io_timeout_ms=500)
|
|
|
|
# Main loop will read the range and print it every second.
|
|
while True:
|
|
print("Range: {0}mm".format(tof.get_range()))
|
|
time.sleep(1.0)
|