實驗設備
(1)蜂鳴器x1。
(2)杜邦線公母x2
Step1)無源蜂鳴器的接線
無源蜂鳴器(背面可以看到綠色電路)正極(長腳)接pin 12,負極接地(GND)。
Step2)使用Python透過Raspberry讓蜂鳴器發出聲音,將以下程式儲存成檔案sound.py。
p = GPIO.PWM(channel, frequency)
p.start(dc) # dc 代表占空比,範圍介於0到100
實驗圖片
執行影片
參考資料
http://tangblack.blogspot.tw/2015/02/raspberry-pi-b.html
https://sourceforge.net/p/raspberry-gpio-python/wiki/PWM/