资源简介
树莓派超声波测距代码 Python ,有兴趣的看看。import RPi.GPIO as gpio
import time
超声波测距部分 Python代码
def distance(measure='cm'):
gpio.setmode(gpio.BOARD)
gpio.setup(12, gpio.OUT)
gpio.setup(16, gpio.IN)
gpio.output(12, False)
while gpio.input(16) == 0:
nosig = time.time()
while gpio.input(16) == 1:
sig = time.time()
代码片段和文件信息
import RPi.GPIO as gpio
import time
def distance(measure=‘cm‘):
gpio.setmode(gpio.BOARD)
gpio.setup(12 gpio.OUT)
gpio.setup(16 gpio.IN)
gpio.output(12 False)
while gpio.input(16) == 0:
nosig = time.time()
while gpio.input(16) == 1:
sig = time.time
评论
共有 条评论