文章图片
文章图片
文章图片
import RPi.GPIO as GPIO
import timetrig = 2def init():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(trig, GPIO.OUT, initial=GPIO.HIGH)
passdef beep(seconds):
GPIO.output(trig, GPIO.LOW)
time.sleep(seconds)
GPIO.output(trig, GPIO.HIGH)def beepBatch(seconds, timespan, counts):
for i in range(counts):
beep(seconds)
time.sleep(timespan)init()
# beep(0.1)
beepBatch(0.1, 0.3, 3)GPIO.cleanup()
【树莓派 有源蜂鸣器】控制的是GPIO02,beepBatch(蜂鸣器响应时间,蜂鸣器停顿时间,蜂鸣器响应次数)