引脚

GPIO 17 3.5V GND 三根线

图片

代码

import RPi.GPIO as GPIOimport timePIN_NO = 17  # GPIO编号,可自定义GPIO.setmode(GPIO.BCM)GPIO.setup(PIN_NO, GPIO.OUT)# 哔1次,时长作为参数传递def beep(seconds):    GPIO.output(PIN_NO, GPIO.HIGH)    time.sleep(seconds)    GPIO.output(PIN_NO, GPIO.LOW)# 哔N次,时长、间隔时长、重复次数作为参数传递def beepAction(secs, sleepsecs, times):    for i in range(times):        beep(secs)        time.sleep(sleepsecs)beepAction(0.01,0.01,3000)

效果

bi~~bibi~~