引脚
GPIO 17 3.5V GND 三根线
图片
代码
import RPi.GPIO as GPIO
import time
PIN_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~~